-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added restoreMocks config option * Changed tests to use jest.spyOn, since that's what restore impacts * Changed tests to use correct toHaveBeenCalled() syntax * Added changelog entry
- Loading branch information
Showing
22 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
|
||
test('suite with auto-restore', () => { | ||
const result = runJest('auto-restore-mocks/with-auto-restore'); | ||
expect(result.status).toBe(0); | ||
}); | ||
|
||
test('suite without auto-restore', () => { | ||
const result = runJest('auto-restore-mocks/without-auto-restore'); | ||
expect(result.status).toBe(0); | ||
}); |
22 changes: 22 additions & 0 deletions
22
integration-tests/auto-restore-mocks/with-auto-restore/__tests__/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const TestClass = require('../'); | ||
const localClass = new TestClass(); | ||
|
||
test('first test', () => { | ||
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD'); | ||
expect(localClass.test()).toEqual('ABCD'); | ||
expect(localClass.test).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('second test', () => { | ||
expect(localClass.test()).toEqual('12345'); | ||
expect(localClass.test.mock).toBe(undefined); | ||
}); |
12 changes: 12 additions & 0 deletions
12
integration-tests/auto-restore-mocks/with-auto-restore/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = class Test { | ||
test() { | ||
return '12345'; | ||
} | ||
}; |
6 changes: 6 additions & 0 deletions
6
integration-tests/auto-restore-mocks/with-auto-restore/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node", | ||
"restoreMocks": true | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
integration-tests/auto-restore-mocks/without-auto-restore/__tests__/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const TestClass = require('../'); | ||
const localClass = new TestClass(); | ||
|
||
describe('without an explicit restore', () => { | ||
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD'); | ||
|
||
test('first test', () => { | ||
expect(localClass.test()).toEqual('ABCD'); | ||
expect(localClass.test).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('second test', () => { | ||
expect(localClass.test()).toEqual('ABCD'); | ||
expect(localClass.test).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
|
||
describe('with an explicit restore', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test('first test', () => { | ||
jest.spyOn(localClass, 'test').mockImplementation(() => 'ABCD'); | ||
expect(localClass.test()).toEqual('ABCD'); | ||
expect(localClass.test).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('second test', () => { | ||
expect(localClass.test()).toEqual('12345'); | ||
expect(localClass.test.mock).toBe(undefined); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
integration-tests/auto-restore-mocks/without-auto-restore/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = class Test { | ||
test() { | ||
return '12345'; | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
integration-tests/auto-restore-mocks/without-auto-restore/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters