Inconsistent Id between render
KevinYobeth opened this issue · 2 comments
KevinYobeth commented
Describe the bug
I'm using a snapshot test from jest which snapshot the DOM and checks for the diff on every test. The problem is the id on react-checkbox-tree is always changing. Hence I can't get the constant snapshot.
Reproduction steps
- Build a snapshot testing using jest.
- Run the test
- Run the test again, the snapshot result should be different
Expected behavior
Provide a way to not randomize the id, for example on MUI, we could add this snippet to lock the id randomization process
global.Math.random = jest.fn().mockImplementation(() => 1);
jakezatecky commented
If the id
property is not set, the tree generates a random UUID with nanoid
. When doing testing, you should supply id
. E.g.:
<CheckboxTree id="test-id" ... />
I am looking to remove the random ID generation in v2.0 (a breaking change) due to a variety of reasons, one of them being inconsistent renders.
KevinYobeth commented
Cool, thanks! It works perfectly.