New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support beforeinput event. #8411
Conversation
Thanks for taking the time to open a PR!
|
packages/driver/src/cy/keyboard.ts
Outdated
@@ -801,6 +803,7 @@ export class Keyboard { | |||
let eventConstructor = 'KeyboardEvent' | |||
let cancelable = true | |||
let addModifiers = true | |||
let inputType = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will add the inputType
to every event since it's not initialized as undefined
. Since we don't test for extra properties we should add a test for that.
I'll take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. It should be written in that way.
.type(testString, { noUpdate: true }) | ||
|
||
cy.contains('[data-slate-string="true"]', testString) | ||
.should('be.visible') | ||
|
||
cy.get('[data-slate-editor="true"]') | ||
.type('{ctrl}{shift}{backspace}', { release: false, noUpdate: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing the noUpdate options here and the test still passed, is there a test case that fails w/o the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. noUpdate
isn't necessary.
I added it because there were some cases when cy.type()
breaks the html structure inside slatejs. It seems that it was because beforeinput
part was buggy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason you previously needed noUpdate was due to the event not being set as cancelable https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event, fixed now so we will respect a cancelled event and not perform the default action
5c228b6
to
a0b70ab
Compare
…einput cancelable
made changes, I added tests in type_spec for beforeinput and verified it passes the slate spec before removing it, since the event tests cover it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sainthkh if you could look at the changes in the last commit and give them a review, we can merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I only did some minor changes.
- Fixed the test failures.
- Removed console.log comments.
|
beforeInput
event / does not work with slate.js #7088User facing changelog
beforeinput
event to solve slate.js issue.Additional details
Why was this change necessary?
Cypress cannot be used to test some applications that use
beforeinput
events like slate.jsWhat is affected by this change?
N/A
Any implementation details to explain?
inputType
to decide what to do. So, I had to decide it based on the key combo and the spec.noUpdate
option had to be introduced tocy.type()
. Because slatejs handles its own state and the text updated by Cypress causes errors.How has the user experience changed?
You can test slatejs with Cypress.
PR Tasks
cypress-documentation
? => coming soon after the approvaltype definitions
?cypress.schema.json
?