Skip to content

Commit

Permalink
[jest] restoring mock now correctly clears mock results
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 7, 2018
1 parent 15e2483 commit 718a9fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions packages/kbn-pm/src/commands/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const noop = () => {

afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

test('handles dependencies of dependencies', async () => {
Expand Down Expand Up @@ -96,8 +97,6 @@ test('handles dependencies of dependencies', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
expect(logMock.mock.calls).toMatchSnapshot('logs');
});
Expand Down Expand Up @@ -127,8 +126,6 @@ test('does not run installer if no deps in package', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
expect(logMock.mock.calls).toMatchSnapshot('logs');
});
Expand All @@ -143,7 +140,7 @@ test('handles "frozen-lockfile"', async () => {
const projects = new Map([['kibana', kibana]]);
const projectGraph = buildProjectGraph(projects);

const logMock = jest.spyOn(console, 'log').mockImplementation(noop);
jest.spyOn(console, 'log').mockImplementation(noop);

await BootstrapCommand.run(projects, projectGraph, {
extraArgs: [],
Expand All @@ -153,8 +150,6 @@ test('handles "frozen-lockfile"', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
});

Expand All @@ -177,16 +172,14 @@ test('calls "kbn:bootstrap" scripts and links executables after installing deps'
const projects = new Map([['kibana', kibana], ['bar', bar]]);
const projectGraph = buildProjectGraph(projects);

const logMock = jest.spyOn(console, 'log').mockImplementation(noop);
jest.spyOn(console, 'log').mockImplementation(noop);

await BootstrapCommand.run(projects, projectGraph, {
extraArgs: [],
options: {},
rootPath: '',
});

logMock.mockRestore();

expect(mockLinkProjectExecutables.mock.calls).toMatchSnapshot('link bins');
expect(mockRunScriptInPackageStreaming.mock.calls).toMatchSnapshot('script');
});
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/utils/link_project_executables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ expect.addSnapshotSerializer(stripAnsiSnapshotSerializer);

afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

describe('bin script points nowhere', () => {
Expand All @@ -102,7 +103,6 @@ describe('bin script points to a file', () => {
// noop
});
await linkProjectExecutables(projectsByName, projectGraph);
logMock.mockRestore();

expect(getFsMockCalls()).toMatchSnapshot('fs module calls');
expect(logMock.mock.calls).toMatchSnapshot('logs');
Expand Down

0 comments on commit 718a9fa

Please sign in to comment.