Git Product home page Git Product logo

Comments (15)

sbaechler avatar sbaechler commented on May 30, 2024 1

I gave it a try. The tests are passing but I have not checked it with my project yet.

from jsdom-testing-mocks.

sbaechler avatar sbaechler commented on May 30, 2024 1

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.

trurl-master avatar trurl-master commented on May 30, 2024 1

@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.

trurl-master avatar trurl-master commented on May 30, 2024 1

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.

trurl-master avatar trurl-master commented on May 30, 2024

@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.

sbaechler avatar sbaechler commented on May 30, 2024

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.

trurl-master avatar trurl-master commented on May 30, 2024

@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.

sbaechler avatar sbaechler commented on May 30, 2024

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.

trurl-master avatar trurl-master commented on May 30, 2024

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.

trurl-master avatar trurl-master commented on May 30, 2024

Hey @sbaechler! Could you check the 1.10.0-beta.0? If it works for your case

from jsdom-testing-mocks.

sbaechler avatar sbaechler commented on May 30, 2024

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.

trurl-master avatar trurl-master commented on May 30, 2024

I'm not sure I follow, configMocks doesn't actually mock anything. Do you call mockResizeObserver within the test module?

from jsdom-testing-mocks.

trurl-master avatar trurl-master commented on May 30, 2024

@sbaechler hey! any update? I would really use your input on this one

from jsdom-testing-mocks.

antoninbas avatar antoninbas commented on May 30, 2024

@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.

antoninbas avatar antoninbas commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.