facebook / facebook/relay

[relay-test-utils] createMockEnvironment expects jest to be defined

Open
#4,228 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

The `package.json` file of `relay-test-utils` does not require `jest`, but attempting to use `createMockEnvironment` in any test runner except for `jest` will result in the following error:

```
ReferenceError: jest is not defined
at mockDisposableMethod (node_modules/relay-test-utils/lib/RelayModernMockEnvironment.js:40:17)
at Object.createMockEnvironment (node_modules/relay-test-utils/lib/RelayModernMockEnvironment.js:354:5)
```

It looks like `RelayModernMockEnvironment` utilizes `jest.fn` under the hood to [create mock methods](https://github.com/facebook/relay/blob/v14.1.0/packages/relay-test-utils/RelayModernMockEnvironment.js#L52) on the `Environment` object.

This issue prevents users from using `createMockEnvironment` with test runners such as [vitest](https://vitest.dev/guide/why.html), `mocha`, `jasmine`, [ava](https://github.com/avajs/ava), etc.

Reproduction using `mocha`: https://glitch.com/edit/#!/frost-tulip-polka

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.