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/integration/spec.js stubs the
window.open
method usingcy.stub()
. Because the application executeswindow.open
after the click we create the method stub aftercy.visit
- cypress/integration/spy-before-load.js starts spying on
console.log
duringcy.visit
to confirm thatconsole.log('hello')
is called when the page loads.