Skip to content

Commit

Permalink
Enable restoreMocks Jest setting (MetaMask#794)
Browse files Browse the repository at this point in the history
The `restoreMocks` Jest setting has been enabled, which will
automatically restore any mocks created using Jest after each test. See
here for more information: https://jestjs.io/docs/configuration#restoremocks-boolean

Note that this will not affect standalone Jest mocks. It only affects
mocks that replace a method/field on a pre-existing object.

A manual mock restoration was removed from the CurrencyRateController
tests, as the mock should now be restored automatically instead.
Gudahtt authored Apr 21, 2022
1 parent e76c545 commit 814c99d
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -16,14 +16,14 @@ module.exports = {
},
moduleFileExtensions: ['js', 'json', 'ts', 'node'],
preset: 'ts-jest',
// TODO: Enable resetMocks and restoreMocks
// TODO: Enable resetMocks
// "resetMocks" resets all mocks, including mocked modules, to jest.fn(),
// between each test case.
// resetMocks: true,
// "restoreMocks" restores all mocks created using jest.spyOn to their
// original implementations, between each test. It does not affect mocked
// modules.
// restoreMocks: true,
restoreMocks: true,
setupFiles: ['./tests/setupTests.ts'],
testEnvironment: 'jsdom',
testRegex: ['\\.test\\.(ts|js)$'],
2 changes: 0 additions & 2 deletions src/assets/CurrencyRateController.test.ts
Original file line number Diff line number Diff line change
@@ -34,10 +34,8 @@ const getStubbedDate = () => {
};

describe('CurrencyRateController', () => {
const realDate = Date.now;
afterEach(() => {
nock.cleanAll();
global.Date.now = realDate;
});

it('should set default state', () => {

0 comments on commit 814c99d

Please sign in to comment.