I am testing some code that uses jQuery to bind click events, and I am having a problem with the test running before the click event is bound.
I want to avoid putting arbitrary waits in the test, so I was trying to find some way to check if the event is bound, and then I can wait for this before making test assertions.
I came up with this super dirty approach in the console:
$._data($('.element-being-tested')[0], 'events' ).click[0].handler.toString().includes('something I know is in the function')
But I cant transfer this to cypress, because Cypress.$._data()
doesn't exist.
How do check if a query event is bound?
Instead of directly testing that the event exists, you could use Cypress retry-ability to keep testing the event's affect, something like
cy.get('.element-that-changes-after-event').then($target => {
// use closure to get a reference to changing element
cy.get('.element-being-tested')
.should($clickable => { // .should(cb) callback function will be retried
$clickable.click()
expect($target.text()).to.equal('Content that appears after click event')
});
});
See Assert class name contains heading-
There may be a simpler way to do this, please post your test.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加