Skip to content

calling rerender causes remounting #1264

@kasir-barati

Description

@kasir-barati
  • @testing-library/react version: 14.1.2
  • Testing Framework and version: jest, 29.7.0
  • DOM Environment: "jest-environment-jsdom": "^29.7.0"

Relevant code or config:

custom hook:

https://github.com/kasir-barati/my-nextjs-journey/blob/main/libs/hooks/use-update-effect.hook.ts

Test case:

https://github.com/kasir-barati/my-nextjs-journey/blob/main/libs/hooks/use-update-effect.hook.spec.tsx

What you did:

I was just making sure that my hook reset the useRef on component unmount and not rerender (like when your states changes and react rerenders it), So I wrote the mentioned unit test to check that out.

What happened:

https://github.com/kasir-barati/my-nextjs-journey/blob/main/README.md#bug

Reproduction:

https://github.com/kasir-barati/my-nextjs-journey/

Problem description:

AFAIK rerender should not cause useEffect to call cleanup callback since it should be invoked only when the component is unmounted. But here it is not the case. I thought something is wrong with the testing library. But I am not 100% sure and also not does not have the confident to do that. So please feel free to enlighten me on what IDK. 🙏

Suggested solution:

Do not have any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions