This is an example showing how to stub window
and console
calls.
The application index.html has a single button that executes window.open
on click. The application also prints "hello" to the console as soon as it loads.
- cypress/e2e/spec.cy.js stubs the
window.open
method usingcy.stub()
. Because the application executeswindow.open
after the click we create the method stub aftercy.visit
- cypress/e2e/spy-before-load.cy.js starts spying on
console.log
duringcy.visit
to confirm thatconsole.log('hello')
is called when the page loads.