You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use jest, @testing-library/react, and Mock Service Worker to do App-level integration testing (if I ever get around to writing a blog post about it I'll link it herehttps://hmh.engineering/want-to-increase-your-quality-and-reduce-your-deployment-times-meet-app-level-integration-testing-308a38cbb321 - it's been great in helping us slim down our expensive Selenium end to end suites) and that involves mocking data endpoints for a particular scenario, rendering an app, and performing semantic queries to emulate end user testing. The app might have a Router inside it with several different routes, so what we currently do is set the global test URL on a per-test basis before rendering the app:
describe('Testing my app on myRoute1: ', () => {
beforeAll(() => {
window.history.replaceState('', '', '/myRoute1');
render(<App />);
});
Another test for a different route might look like:
describe('Testing my app on myRoute1 with some pre-supplied query parameters: ', () => {
beforeAll(() => {
window.history.replaceState('', '', '/myRoute1?sort=apples');
render(<App />);
});
We should be able to utilise the out-of-the-box jest feature for testUrl rather than messing with the window object in these tests.
Example
Those examples above would become something like:
describe('Testing my app on myRoute1 with some pre-supplied query parameters: ', () => {
beforeAll(() => {
jest.setTestUrl('/myRoute1?sort=apples');
render(<App />);
});
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🚀 Feature Proposal
https://jestjs.io/docs/en/configuration#testurl-string allows you to set the URL for the JSDOM environment at the jest.config.js / package.json level, but there is no way to set this attribute on a per-test basis. A
setTestUrl
method on the jest object would allow you to set the URL on the fly in tests (similar tosetTimeout
https://jestjs.io/docs/en/jest-object#jestsettimeouttimeout).Motivation
We use jest, @testing-library/react, and Mock Service Worker to do App-level integration testing (
if I ever get around to writing a blog post about it I'll link it herehttps://hmh.engineering/want-to-increase-your-quality-and-reduce-your-deployment-times-meet-app-level-integration-testing-308a38cbb321 - it's been great in helping us slim down our expensive Selenium end to end suites) and that involves mocking data endpoints for a particular scenario, rendering an app, and performing semantic queries to emulate end user testing. The app might have a Router inside it with several different routes, so what we currently do is set the global test URL on a per-test basis before rendering the app:Another test for a different route might look like:
We should be able to utilise the out-of-the-box jest feature for
testUrl
rather than messing with the window object in these tests.Example
Those examples above would become something like:
Pitch
Why does this feature belong in the Jest core platform?
Common feature proposals that do not typically make it to core:
The text was updated successfully, but these errors were encountered: