Skip to content
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

Default mock for the window.print call in browser mode #7375

Open
4 tasks done
charlieforward9 opened this issue Jan 29, 2025 · 2 comments
Open
4 tasks done

Default mock for the window.print call in browser mode #7375

charlieforward9 opened this issue Jan 29, 2025 · 2 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@charlieforward9
Copy link

Clear and concise description of the problem

I see there are default mocks for the window.confirm, window.alert, etc... calls but nothing for print.

Given this open, unaddressed and seemingly un-workaroundable issue: #7290 (and the linked issues within), I cannot mock my reactToPrint module within my tests, so the print window pops up, and on my CI tests, it hangs the runner. Ive tried to mock the print call myself, but cant seem to get it right.

Suggested solution

Add a default mock for the window.print call:

https://github.com/vitest-dev/vitest/blob/main/packages/browser/src/client/tester/dialog.ts#L21-L25

(i think)

Alternative

No response

Additional context

No response

Validations

@hi-ogawa
Copy link
Contributor

I think we can include window.print there. PR welcome 👍

Ive tried to mock the print call myself, but cant seem to get it right.

It should be possible by simply patching a global or https://vitest.dev/guide/mocking.html#globals. If that's not working, then the issue could be somewhere else (like how reactToPrint uses it). Can you prepare reproduction just in case? (so you can also confirm the fix actually works for you).

@hi-ogawa hi-ogawa added enhancement New feature or request p3-minor-bug An edge case that only affects very specific usage (priority) and removed enhancement: pending triage enhancement New feature or request labels Jan 29, 2025
@charlieforward9
Copy link
Author

From MatthewHerbst/react-to-print#782, I now understand that we do not use window.print() directly, so this PR will not help me like I thought it would.

While I'd be honored to attain contributor status in this repo, I must prioritize the release our our app right now - being a team of 2 is tough...

Please feel free to assign me to this so I can find it easier in my backlog when my time frees up. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants