1

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?

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Nick.K
  • 320
  • 6
  • 11

1 Answers1

0

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

user3568791
  • 676
  • 1
  • 7
  • 22