jpuri / react-draft-wysiwyg

A Wysiwyg editor build on top of ReactJS and DraftJS. https://jpuri.github.io/react-draft-wysiwyg
MIT License
6.41k stars 1.16k forks source link

Use a function to generate an ID if you need to #538

Open sontek opened 6 years ago

sontek commented 6 years ago

I can't use react snapshots when testing my use of the WYSIWYG editor because of:

https://github.com/jpuri/react-draft-wysiwyg/blob/9be932d1a00f26468aa349b0118f310ba212f0b7/src/Editor/index.js#L103

If you use a function, then I could target it and mock it.

sontek commented 6 years ago

Right now I'm doing:

    beforeEach(
        () => {
            StyleSheetTestUtils.suppressStyleInjection();
            Math.random = jest.fn(() => 123);
        }
    );

which I don't like, because I do use Math.random in other places.

jpuri commented 6 years ago

Hey @sontek , can you try to pass wrapperId and check, that should work.

aneeq-dev commented 7 months ago

Hey @sontek I know its been too late to comment here Just commenting for helping others

If snapshots are keep updating, as because of wrapper ID is keep updating. So just provide wrapperID prop to the react-draft-WYSIWYG Editor as

<Editor wrapperID="some-id" in the main component of react-draft-WYSIWYG