Spy On window.postMessage Calls

1 · Gleb Bahmutov · Nov. 16, 2022, 3:39 p.m.
Summary
Cypress test runs in the browser in an iframe next to the application's iframe. This makes it extremely simple to spy, stub, and subscribe to the events sent to the application's window object by other windows or by workers via window.postMessage method calls.Spy on the method callsThe simplest way to confirm some code calls window.postMessage is by spying on this method using the cy.spy command. You just need the reference to the window object and the method's name "postMessage" and let the inc...