Closed
Description
Add a new event 'namespace' window:*
where *
is any event you can register on the window
. So a user can do the following:
cy.on('window:hashchange', (e) => {})
This would bind to the window's hashchange
event and be unbound after the test finishes running. It would rebind if the page navigates. Any arbitrary window event can be bound and receives the event as normally binding with window.addEventListener
.
// instead of
cy.window().then((win) => {
const handler = () => {
// handling code
win.removeEventListener('foobar', handler)
}
win.addEventListener('foobar', handler, false)
})
// the user can do this
cy.on('window:foobar', (e) => {
// handling code
})