P粉7454121162023-08-18 10:40:22
Cypress uses different window
in tests and applications. cy.spy(window...
is using the test window, but to monitor the application window, you need to use the cy.window()
command.
let spy; cy.window().then(appWindow => { spy = cy.spy(appWindow, 'clearInterval') }) ... later expect(spy).to.have.been.calledOnce
But there may be another complication, because cy.clock()
puts clearInterval()
in the proxy so that the application's timing function can be controlled, so You may not be able to monitor it.
If you find that it still doesn't work properly, please get the return value of cy.clock()
and see if the call information is attached.
let clock; beforeEach(() => { clock = cy.clock(new Date()) })
Or specify clearInterval
should not be proxied
beforeEach(() => { cy.clock(new Date(), ['Date', 'setInterval']) // 仅代理Date和setInterval })