jakezatecky / react-checkbox-tree

A simple and elegant checkbox tree for React.

Home Page:https://jakezatecky.github.io/react-checkbox-tree/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent Id between render

KevinYobeth opened this issue · comments

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

  1. Build a snapshot testing using jest.
  2. Run the test
  3. 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);

Screenshots
image 37

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.

Cool, thanks! It works perfectly.