Unable to run Jest Snapshot tests with jest-puppeteer

Viewed 136

I just added jest-puppeteer to include it in my testing suites. Part of the setup is to remove testEnvironment:"jsdom" in my jest.config.js according to https://github.com/smooth-code/jest-puppeteer. Considering I'm using Next.js which may be running on the server and doesn't have access to browser objects such as document, How do I run my snapshot tests without testEnvironment:"jsdom"? I was looking for a way to change jest configuration programmatically but I couldn't find any. Is there an approach to doing this?

1 Answers

same case here.

You can do the following:

  1. Create two separated configs for the unit and for the integration testing.
  2. Name your unit and integration tests with different suffixes: .unit.js || .int.js
  3. Create different commands in the package.json

jest.config.unit.js:

{testEnvironment: 'jsdom', testRegex: "\\.unit\\.ts"}

jest.config.integration.js:

{preset: "jest-puppeteer", testRegex: "\\.int\\.ts"}

package.json:

"unit": "jest -c jest.config.unit.js",
"int": "jest -c jest.config.integration.js",

And in the test folder:

/unit/test.unit.js

/int/test.int.js

Related