I am trying to use Jest with a new CRA project, but I am facing a problem when trying to use the findByText
function. I installed:
yarn add -D jest-environment-jsdom-sixteen
And run my tests with react-scripts test --env=jest-environment-jsdom-sixteen
. It works fine if I do this solution that I encountered while reading these issues here:
- https://github.com/testing-library/dom-testing-library/issues/477
- https://github.com/testing-library/react-testing-library/issues/662
- https://github.com/testing-library/react-testing-library/issues/731
However I am also using the Jest plugin from VS code and tests do not pass with it. I have tried to do this in my jest.config.js
as suggested in the docs:
module.exports = {
testEnvironment: 'jest-environment-jsdom-sixteen',
};
But it still does not work.
Thanks in advance.
Testing MutationObserver with Jest: Try this, it worked for me, on a similar error:
npm i -D mutationobserver-shim
import "mutationobserver-shim";
in setupTests.js