Skip to content

Commit

Permalink
test and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 4, 2022
1 parent 79fdfdb commit 37cc983
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

### Fixes

- `[@jest/transform]` Update dependency package `pirates` to 4.0.4 ([#12136](https://github.com/facebook/jest/pull/12136))
- `[jest-environment-node]` Add `AbortSignal` ([#12157](https://github.com/facebook/jest/pull/12157))
- `[jest-environment-node]` Add Missing node global `performance` ([#12002](https://github.com/facebook/jest/pull/12002))
- `[jest-runtime]` Handle missing `mocked` property ([#12002](https://github.com/facebook/jest/pull/12002))
- `[@jest/transform]` Update dependency package `pirates` to 4.0.4 ([#12213](https://github.com/facebook/jest/pull/12213))

### Chore & Maintenance

Expand Down
45 changes: 44 additions & 1 deletion e2e/__tests__/testEnvironment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

import {json as runWithJson} from '../runJest';
import {tmpdir} from 'os';
import * as path from 'path';
import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
import runJest, {json as runWithJson} from '../runJest';
import * as testFixturePackage from '../test-environment/package.json';

const DIR = path.resolve(tmpdir(), 'test-env-no-mocked');

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

it('respects testEnvironment docblock', () => {
expect(testFixturePackage.jest.testEnvironment).toEqual('node');

Expand All @@ -16,3 +24,38 @@ it('respects testEnvironment docblock', () => {
expect(result.success).toBe(true);
expect(result.numTotalTests).toBe(3);
});

it('handles missing `mocked` property', () => {
createEmptyPackage(DIR);
writeFiles(DIR, {
'env.js': `
const Node = require('${require.resolve('jest-environment-node')}');
module.exports = class Thing extends Node {
constructor(...args) {
super(...args);
this.moduleMocker.mocked = undefined;
}
};
`,
'test.js': `
/**
* @jest-environment ./env.js
*/
jest.mocked();
test('halla', () => {
expect(global.thing).toBe('nope');
});
`,
});

const {exitCode, stderr} = runJest(DIR);

expect(exitCode).toBe(1);
expect(stderr).toContain(
'Your test environment does not support `mocked`, please update it.',
);
});
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ export default class Runtime {
this._moduleMocker.mocked?.bind(this._moduleMocker) ??
(() => {
throw new Error(
'Your test environment does not support `mocked`, please update it',
'Your test environment does not support `mocked`, please update it.',
);
});

Expand Down

0 comments on commit 37cc983

Please sign in to comment.