GithubHelp home page GithubHelp logo

Comments (6)

mikeborozdin avatar mikeborozdin commented on August 16, 2024 2

@kvet ,

That's an interesting proposal! I'll look into it. It might be difficult to implement cleanupReactHooks(forWrapper), since the library has no knowledge of components on Enzyme wrappers. But I can certainly add a method for firing all cleaning up functions.

from jest-react-hooks-shallow.

mikeborozdin avatar mikeborozdin commented on August 16, 2024

Hi @kvet ,

Thank you for submitting the issue. Unfortunately, as the FAQ says the library has no way of trigger cleanup functions when a component unmounts. The cleanup functions are only called before invoking the same effect again.

from jest-react-hooks-shallow.

kvet avatar kvet commented on August 16, 2024

Hi @mikeborozdin ,

I didn't notice this. However, maybe it is possible to at least export some function to perform a manual cleanup?

from jest-react-hooks-shallow.

mikeborozdin avatar mikeborozdin commented on August 16, 2024

Hi @kvet ,

Do you have an example on how the code doing that would look like? What are you trying to achieve?

If you have to invoke a cleanup manually in a test, is there much point in testing it?

from jest-react-hooks-shallow.

kvet avatar kvet commented on August 16, 2024

In my scenario, I want to test cleanup function on unmount. So, that unmount is already done with wrapper.unmount() method. And it should not be a problem for those who really want to test this, call an additional method here like cleanupReactHooks().

This of course can cause problems with multiple components testing on the one test. But I guess we can provide wrapper instance to that method in order to call hooks cleanups for specific component. Something like cleanupReactHooks(forWrapper).

from jest-react-hooks-shallow.

MilosRasic avatar MilosRasic commented on August 16, 2024

👍 for this

In my case, I'm trying to test an event listener attached to document in an effect. Without cleanup on unmount, every test case will add another listener to document which will never be cleaned up. Makes toHaveBeenCalledTimes() really unpredictable.

from jest-react-hooks-shallow.

Related Issues (20)

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.