-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Expose jsdom to global environment #2460
Comments
On my use case I need to change the As |
|
@cpojer It does not have the same behavior than the |
I have a script that does different things based on whether it is at the top level or not. |
In our case, we have traditionally used Jest to test our React components using snapshots or, sometimes, more involved tests around events - those tests require a full mock DOM. Our components are held in a component library monorepo, and included in a separate project that does server-side rendering later on. We recently had an issue where a component had an unchecked reference to The solution to this is easy - just check if Some sort of way to access and modify |
@simon360 i think what you're looking for is this http://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html#multi-project-runner-configuration-overhaul |
Oh, that looks perfect. Thanks @aaronabramov! (I'd love to use flow, but it isn't a good fit for our project right now. It's on our radar, but we just can't set the time aside for it at the moment.) |
You can use https://facebook.github.io/jest/docs/en/configuration.html#testenvironment-string |
I am using a library that access "protocol", "host" and "port" on the location object. @cpojer's work around does work if I do this: Object.defineProperty(window.location, "protocol", {
writable: true,
value: "http:"
});
Object.defineProperty(window.location, "host", {
writable: true,
value: "localhost:14187"
});
Object.defineProperty(window.location, "port", {
writable: true,
value: "14187"
}); But fails if I try to do this Object.defineProperty(window, "location", {
writable: true,
value: {
protocol: "http:",
host: "localhost:14187",
port: "14187"
}
}); I believe that exposing jsdom would actually make this solution a lot neater: jest.jsdom.changeURL("http://localhost:14187") |
Not planning to do this in jest-environment-jsdom. People can fork jest-environment-jsdom and build their own environment on top of it which will expose any globals people need. |
FWIW, here's an up-to date template: https://github.com/mes/jest-environment-jsdom-external-scripts |
What if I need to configure |
Then you can use a custom environment. |
oh lol, thanks! |
As of Jest 22/JSDom 11, using |
This is a question/discussion topic.
While discussing this issue #2453 and earlier conversation here #890 I came to conclusion that it may be worth exposing
jsdom
somehow to the environment. What do you think?@cpojer @DmitriiAbramov
The text was updated successfully, but these errors were encountered: