-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mocking window.print #894
Comments
Stubbing As long as its stubbed it will not call through to the native function. You're either stubbing the function too late (so after your app calls it), or you're doing something like transitioning to another page which then loses the stub. You can use this event to always stub it on every page transition: https://docs.cypress.io/api/events/catalog-of-events.html#Window-Before-Load |
Closing this as this is a question, not a bug. |
confirmed, sorry for the noise J |
No problem. For the record you can stub anything so long as it is set to { configurable: true } when you do this: Object.getOwnPropertyDescriptor(obj, 'prop') If its set to false you cannot stub it - and the best practice in that case is to wrap that API in your own function and just stub that function. For instance you cannot stub So in that case const myObj = {}
myObj.href = function (url) {
window.location.href = url
} // in cypress code
cy.stub(myObj, 'href') |
Hello @brian-mann My code looks like |
engine :
but force close and print is still stuck ( not cancel / close )
force close
|
@yogithesymbian Did you manage to solve it? I am also in a similar situation perhaps I wanted to print the content in PDF format and I don't care about closing the popup. If you have a code snippet, feel free to share it. |
Had 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
also with
but each time I click on the printing button, I'm prompted with the browser print preview box.
Thank you!
The text was updated successfully, but these errors were encountered: