Got a small issue, running the tests though, You mentioned something
about not adding React-Dom to the library since that would deny the purpose of building a 'standalone' component library, if I remember correctly.
Now when I try to run 'yarn test' I'm getting the following error.
Cannot find module 'react-dom' from 'node_modules/@testing-library/react/dist/pure.js'
This is fixed when I add React-Dom to the project.
In the "Adding Tests" section there is an instruction for editing your jest config to use jsdom instead of React DOM which is aimed to eliminate the need for that dependency, did you include that in your config?
Yes I have that included, I have just added React-Dom as a peer dep, as a workaround. It is accessing the config file correctly though, just always wants to go back to ReactDom, but the workaround works, and since we need it anyway for storybook it's fine.
I also have the same issue, only fixed by installing react-dom. It's probably worth mentionning that I did not include the Storybook part in my library and I did not publish on npm. But apart from that it's the same config files.
Also, moving react to peerDependencies does not work with Jest as he seems to need them in order to run the tests (because of the import in Button.test.tsx). Without Jest the packaging seems to work though.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great post,
Got a small issue, running the tests though, You mentioned something
about not adding
React-Dom
to the library since that would deny the purpose of building a 'standalone' component library, if I remember correctly.Now when I try to run 'yarn test' I'm getting the following error.
Cannot find module 'react-dom' from 'node_modules/@testing-library/react/dist/pure.js'
This is fixed when I add React-Dom to the project.
Do you see any way around this?
In the "Adding Tests" section there is an instruction for editing your jest config to use
jsdom
instead of React DOM which is aimed to eliminate the need for that dependency, did you include that in your config?Yes I have that included, I have just added React-Dom as a peer dep, as a workaround. It is accessing the config file correctly though, just always wants to go back to ReactDom, but the workaround works, and since we need it anyway for storybook it's fine.
Thanks again for the blog!
I also have the same issue, only fixed by installing react-dom. It's probably worth mentionning that I did not include the Storybook part in my library and I did not publish on npm. But apart from that it's the same config files.
Also, moving react to peerDependencies does not work with Jest as he seems to need them in order to run the tests (because of the import in Button.test.tsx). Without Jest the packaging seems to work though.