mocking window.print
See original GitHub issueHad anyone tried mocking window.print?
I have a scenario where I need to click on a button that window.print’s something, in order to move to the next step, and the test remains stuck in the browser print dialog box at the moment.
I tried with
cy.visit(url, { onBeforeLoad: win => cy.stub(win, 'print').returns(undefined) })
also with
cy.window(win => cy.stub(win, 'print').returns(undefined))
but each time I click on the printing button, I’m prompted with the browser print preview box.
Thank you!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How can I mock the JavaScript 'window' object using Jest?
I would like to mock window's open function, so I can verify the correct URL is passed in to the open function. Using...
Read more >Mocking window object with Jest - Marek Rozmus - Medium
Mocking window object with Jest” is published by Marek Rozmus. ... First testing the pathname check — new window should be opened when...
Read more >Mocking the window object in unit tests - DEV Community
Hi there! Let's talk about how to properly mock that pesky browser window object in a unit testing environment.
Read more >[Solved]-jest: window.print not implemented-Vue.js
Since window.alert, print and several other browser-specific side effects needs to be stubbed manually. This should preferably be done with Jest, ...
Read more >How to mock global window variables with Jest
While generally everything is extremely easy using Jest, mocking global variables is one thing which is left up to developer. You can…
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @brian-mann I trying to stub print preview but getting, could you please help, Ultimately I want to close print preview or somehow avoid from opening,
expected print to have been called exactly once, but it was never called
My code looks like cy.window().then(win => { cy.stub(win, ‘print’).as(‘print’); });
cy.get(‘my locator’).click(); // this click event opens print widdow(Only after closing print preview window my API call happens). cy.get(‘@print’).should(‘have.been.calledOnce’);