Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(e2e): consolidate all end-to-end tests of fake timers (#12595)
- Loading branch information
1 parent
abca0fe
commit f6219d1
Showing
42 changed files
with
215 additions
and
207 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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. | ||
*/ | ||
|
||
import runJest from '../runJest'; | ||
|
||
describe('enableGlobally', () => { | ||
test('enables fake timers from Jest config', () => { | ||
const result = runJest('fake-timers/enable-globally'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('useFakeTimers', () => { | ||
test('enables fake timers from Jest object', () => { | ||
const result = runJest('fake-timers/use-fake-timers'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('requestAnimationFrame', () => { | ||
test('fakes requestAnimationFrame', () => { | ||
const result = runJest('fake-timers/request-animation-frame'); | ||
|
||
expect(result.stderr).toMatch('requestAnimationFrame test'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('setImmediate', () => { | ||
test('fakes setImmediate', () => { | ||
const result = runJest('fake-timers/set-immediate'); | ||
|
||
expect(result.stderr).toMatch('setImmediate test'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('useRealTimers', () => { | ||
test('restores timers to the native implementation', () => { | ||
const result = runJest('fake-timers/use-real-timers'); | ||
expect(result.stdout).toMatch('API is not mocked with fake timers.'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); |
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,60 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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. | ||
*/ | ||
|
||
import runJest from '../runJest'; | ||
|
||
describe('enableGlobally', () => { | ||
test('enables fake timers from Jest config', () => { | ||
const result = runJest('fake-timers-legacy/enable-globally'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('useFakeTimers', () => { | ||
test('enables fake timers from Jest object', () => { | ||
const result = runJest('fake-timers-legacy/use-fake-timers'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('requestAnimationFrame', () => { | ||
test('fakes requestAnimationFrame', () => { | ||
const result = runJest('fake-timers-legacy/request-animation-frame'); | ||
|
||
expect(result.stderr).toMatch('requestAnimationFrame test'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('setImmediate', () => { | ||
test('fakes setImmediate', () => { | ||
const result = runJest('fake-timers-legacy/set-immediate'); | ||
|
||
expect(result.stderr).toMatch('setImmediate test'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('useRealTimers', () => { | ||
test('restores timers to the native implementation', () => { | ||
const result = runJest('fake-timers-legacy/use-real-timers'); | ||
expect(result.stdout).toMatch('API is not mocked with fake timers.'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('when mocks are reset', () => { | ||
test('calling resetAllMocks does not break tests', () => { | ||
const result = runJest('fake-timers-legacy/reset-all-mocks'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
|
||
test('setting resetMocks in Jest config does not break tests', () => { | ||
const result = runJest('fake-timers-legacy/reset-mocks'); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"name": "enable-globally-legacy", | ||
"jest": { | ||
"timers": "legacy" | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
...legacy/requestAnimationFrame/package.json → ...gacy/request-animation-frame/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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"name": "request-animation-frame-legacy", | ||
"jest": { | ||
"testEnvironment": "jsdom" | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
e2e/fake-timers-legacy/reset-all-mocks/__tests__/resetAllMocks.test.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,25 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. 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'; | ||
|
||
test('works before resetAllMocks is called', () => { | ||
jest.useFakeTimers(); | ||
const f = jest.fn(); | ||
setTimeout(f, 0); | ||
jest.runAllTimers(); | ||
expect(f).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('works after resetAllMocks is called', () => { | ||
jest.resetAllMocks(); | ||
jest.useFakeTimers(); | ||
const f = jest.fn(); | ||
setTimeout(f, 0); | ||
jest.runAllTimers(); | ||
expect(f).toHaveBeenCalledTimes(1); | ||
}); |
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,7 @@ | ||
{ | ||
"name": "reset-all-mocks", | ||
"jest": { | ||
"resetMocks": false, | ||
"timers": "legacy" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"name": "reset-mocks", | ||
"jest": { | ||
"resetMocks": true, | ||
"timers": "legacy" | ||
} | ||
} |
File renamed without changes.
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 @@ | ||
{ | ||
"name": "set-immediate-legacy", | ||
"jest": { | ||
"timers": "legacy" | ||
} | ||
} |
File renamed without changes.
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,3 @@ | ||
{ | ||
"name": "use-fake-timers-legacy" | ||
} |
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,6 @@ | ||
{ | ||
"name": "use-real-timers-legacy", | ||
"jest": { | ||
"timers": "legacy" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"name": "enable-globally", | ||
"jest": { | ||
"timers": "modern" | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
...modern/requestAnimationFrame/package.json → ...mers/request-animation-frame/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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"name": "request-animation-frame", | ||
"jest": { | ||
"testEnvironment": "jsdom" | ||
} | ||
|
Oops, something went wrong.