Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed tests to use jest.spyOn, since that's what restore impacts
  • Loading branch information
gricard committed Jan 16, 2018
commit d4cb6097d3f8f1d5dc2dd7217a03981b61e1d213
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@

'use strict';

jest.mock('../');
const importedFn = require('../');
const localFn = jest.fn(() => 8675309);
const TestClass = require('../');
const localClass = new TestClass();

test('first test', () => {
importedFn();
const returnVal = localFn();

expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(returnVal).toBe(8675309);
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD');
expect(localClass.test()).toEqual('ABCD');
expect(localClass.test.mock.calls.length).toBe(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toHaveBeenCalledTimes(1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with the others

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. I left that the way it was in the tests for resetMocks. I wasn't sure if it was using that older style for a specific reason or not. Fixed.

As for the changelog, would this be correct? The changes touch jest-cli, jest-config, jest-jasmine2, etc. so I'm not sure which one to place in the beginning of the line. I went with jest-config since it's more related to the config.

* `[jest-config]` Add restoreMocks config option.
  ([#5327](https://github.com/facebook/jest/pull/5327))

});

test('second test', () => {
importedFn();
const returnVal = localFn();

expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(returnVal).not.toBe(8675309);
expect(localClass.test()).toEqual('12345');
expect(localClass.test.mock).toBe(undefined);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

module.exports = () => {};
module.exports = class Test {
test() {
return '12345';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,20 @@

'use strict';

jest.mock('../');

const importedFn = require('../');
const localFn = jest.fn(() => 8675309);
const TestClass = require('../');
const localClass = new TestClass();

describe('without an explicit restore', () => {
test('first test', () => {
importedFn();
const returnVal = localFn();
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD');

expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(returnVal).toBe(8675309);
test('first test', () => {
expect(localClass.test()).toEqual('ABCD');
expect(localClass.test.mock.calls.length).toBe(1);
});

test('second test', () => {
importedFn();
const returnVal = localFn();

expect(importedFn.mock.calls.length).toBe(2);
expect(localFn.mock.calls.length).toBe(2);
expect(returnVal).toBe(8675309);
expect(localClass.test()).toEqual('ABCD');
expect(localClass.test.mock.calls.length).toBe(2);
});
});

Expand All @@ -38,20 +30,13 @@ describe('with an explicit restore', () => {
});

test('first test', () => {
importedFn();
const returnVal = localFn();

expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(returnVal).toBe(8675309);
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD');
expect(localClass.test()).toEqual('ABCD');
expect(localClass.test.mock.calls.length).toBe(1);
});

test('second test', () => {
importedFn();
const returnVal = localFn();

expect(importedFn.mock.calls.length).toBe(1);
expect(localFn.mock.calls.length).toBe(1);
expect(returnVal).not.toBe(8675309);
expect(localClass.test()).toEqual('12345');
expect(localClass.test.mock).toBe(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

module.exports = () => {};
module.exports = class Test {
test() {
return '12345';
}
};