Skip to content

Decide on Jest's default environment #338

Closed
@cpojer

Description

@cpojer

Jest ships with jsdom by default. With the test renderer we don't need jsdom so I recommend people to use the node environment, also in CRA: https://github.com/facebookincubator/create-react-app/blob/master/scripts/utils/create-jest-config.js#L22

However, I expect people would like to continue using enzyme until they are fully bought into snapshot testing and until the test renderer supports all the APIs to put enzyme itself (or a compatible API) on top of the test renderer.

Here are the possible solutions:

  • Remove the testEnvironment config I linked to above. The only downside is that Jest's startup increases by 500ms because jsdom takes 500ms to require. (simply measure require('jsdom');) . This is the easiest fix.
  • Encourage people to install and load jsdom themselves: It's basically const window = require('jsdom').jsdom(...).defaultView;

I don't have strong feelings either way. Personally I'd like to get into a place where jsdom is available but not the default in Jest (maybe with a @jest-env jsdom directive in the header; we haven't finalized our ideas yet).

For CRA, given that people predominantly write web apps, it likely makes sense to take this performance hit and go with option one. It's a bit slower but the saner no-config default.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions