Comments (15)
I gave it a try. The tests are passing but I have not checked it with my project yet.
from jsdom-testing-mocks.
I think this fixed the issue. I am currently on vacation but will test next week in our project.
Thank you for the quick fix.
from jsdom-testing-mocks.
@antoninbas Hey! Yeah, It was a bug in <=1.9, I accidentally forgot a piece of code that called .mockResizeObserver
on the module level. Sorry for the confusion!
from jsdom-testing-mocks.
I will close this as completed. @sbaechler if you have any more issues, please feel free to reopen it. And thank you for your contribution!
from jsdom-testing-mocks.
@sbaechler hi there! Thank you for the issue.
I would need your help with this one. I'm a bit confused. If you're using node
as your environment, why would you need the package? Or do you somehow running some tests using node
as environment and others using jsdom
?
from jsdom-testing-mocks.
Hi Ivan
Yes, we have a large React application that uses Jest as test runner. All tests that test domain logic and don't have a dependency on react-dom are run in a node environment without JSDOM. The idea was that they run faster. I have not really measured if the actually do run faster, but since they don't have to load JSDOM there is less boilerplate.
Jest supports setting the environment on module level.
https://jestjs.io/docs/configuration#testenvironment-string
from jsdom-testing-mocks.
@sbaechler I see. Thank you for clarification. Makes sense. I checked the code and I indeed rely on the presence of window
in some cases. I will need to remove that.
I wonder will this be enough though. Do you mock anything within the modules that use the node
environment? In other words do you run any mock*
functions in these modules?
from jsdom-testing-mocks.
No, not from jsdom-testing-mocks. If I needed a DOM method I would just use the JSDOM environment. The tests in the node environment are mostly Redux reducers, sagas and selectors. The problem here is really the dependency on window
.
from jsdom-testing-mocks.
Got it. I will try to take a look at it this or next week. If you wish to take a look at it yourself, you're always welcome, it shouldn't be too difficult
from jsdom-testing-mocks.
Hey @sbaechler! Could you check the 1.10.0-beta.0? If it works for your case
from jsdom-testing-mocks.
I quickly tested it and the test didn't crash anymore. But it looks like ResizeObserver was also not added to the DOM. I called configMocks() within setupTests.
from jsdom-testing-mocks.
I'm not sure I follow, configMocks
doesn't actually mock anything. Do you call mockResizeObserver
within the test module?
from jsdom-testing-mocks.
@sbaechler hey! any update? I would really use your input on this one
from jsdom-testing-mocks.
@trurl-master is there any guidance on upgrading from 1.9 to 1.10? All my tests are failing when I try to upgrade, which I assume is tied to the resolution of this issue.
This is the error I am getting (repeated 100s of times):
⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
ReferenceError: ResizeObserver is not defined
❯ s.hostConnected node_modules/src/internal/controllers/responsive.controller.ts:22:29
This error originated in "src/App.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "refresh error - other API error". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- This was the last recorded test before the error was thrown, if error originated after test finished its execution.
from jsdom-testing-mocks.
I was missing a call to mockResizeObserver
in my setupTests.ts files
Now I am just confused about why this call was not required with jsdom-testing-mocks v1.9 (my tests were passing), when it seems that it should have been...
from jsdom-testing-mocks.
Related Issues (10)
- Allow adding more properties to the IntersectionDescription HOT 5
- ResizeObserver should fire the onResize handler when ro.observe(elem) is called HOT 4
- TypeError: Cannot redefine property: ResizeObserver (v1.4.0) HOT 2
- Error with type-fest on build project HOT 2
- [Request] Add compatibility with other libraries HOT 8
- Animations aren't captured HOT 7
- `@media not all and ` is not supported HOT 1
- LocalResizeObserver is not a constructor error in v1.10+ HOT 2
- Export `MockedResizeObserver` class
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsdom-testing-mocks.