Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Feb 10, 2024
1 parent f1ea1f7 commit 7cfc9d0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"tempy": "^1.0.0",
"ts-node": "^10.5.0",
"tstyche": "^1.0.0-beta.9",
"typescript": "^5.2.2",
"typescript": "^5.0.4",
"webpack": "^5.68.0",
"webpack-node-externals": "^3.0.0",
"which": "^4.0.0"
Expand Down
39 changes: 21 additions & 18 deletions packages/jest-mock/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import * as util from 'util';
import {type Context, createContext, runInContext, runInNewContext} from 'vm';
import {onNodeVersions} from '@jest/test-utils';
import {ModuleMocker, fn, mocked, spyOn} from '../';

if (!Symbol.dispose) {
Expand Down Expand Up @@ -2441,25 +2442,27 @@ test('`fn` and `spyOn` do not throw', () => {
}).not.toThrow();
});

describe('Explicit Resource Management', () => {
it('jest.fn state should be restored with the `using` keyword', () => {
const mock = jest.fn();
{
using inScope = mock.mockReturnValue(2);
expect(inScope()).toBe(2);
expect(mock()).toBe(2);
}
expect(mock()).not.toBe(2);
});
onNodeVersions('>=18.0.0', () => {
describe('Explicit Resource Management', () => {
it('jest.fn state should be restored with the `using` keyword', () => {
const mock = jest.fn();
{
using inScope = mock.mockReturnValue(2);
expect(inScope()).toBe(2);
expect(mock()).toBe(2);
}
expect(mock()).not.toBe(2);
});

it('should be restored with the `using` keyword', () => {
{
using mockedLog = jest.spyOn(console, 'log');
expect(jest.isMockFunction(console.log)).toBeTruthy();
it('should be restored with the `using` keyword', () => {
{
using mockedLog = jest.spyOn(console, 'log');
expect(jest.isMockFunction(console.log)).toBeTruthy();

console.log('test');
expect(mockedLog).toHaveBeenCalled();
}
expect(jest.isMockFunction(console.log)).toBeFalsy();
console.log('test');
expect(mockedLog).toHaveBeenCalled();
}
expect(jest.isMockFunction(console.log)).toBeFalsy();
});
});
});
3 changes: 2 additions & 1 deletion packages/jest-mock/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
"outDir": "build",
"lib": ["es2021", "ESNext.Disposable"]
},
"include": ["./src/**/*"],
"exclude": ["./**/__tests__/**/*"],
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"declaration": true,
"emitDeclarationOnly": true,
"stripInternal": true,
"lib": ["es2021", "ESNext.Disposable"],

"strict": true,

Expand Down

0 comments on commit 7cfc9d0

Please sign in to comment.