Skip to content

Commit aa0618a

Browse files
committed
make lolex default implementation
1 parent b0ce445 commit aa0618a

File tree

11 files changed

+116
-3
lines changed

11 files changed

+116
-3
lines changed

docs/Configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,9 @@ This option sets the URL for the jsdom environment. It is reflected in propertie
12751275

12761276
Default: `real`
12771277

1278-
Setting this value to `legacy` or `fake` allows the use of fake timers for functions such as `setTimeout`. Fake timers are useful when a piece of code sets a long timeout that we don't want to wait for in a test.
1278+
Setting this value to `fake` or `modern` allows the use of fake timers for functions such as `setTimeout`. Fake timers are useful when a piece of code sets a long timeout that we don't want to wait for in a test.
12791279

1280-
If the value is `modern`, [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers) will be used as implementation instead of Jest's own legacy implementation. This will be the default fake implementation in Jest 27.
1280+
If the value is `legacy`, the old implementation will be used as implementation instead of one backed by [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
12811281

12821282
### `transform` \[object<string, pathToTransformer | \[pathToTransformer, object]>]
12831283

e2e/__tests__/fakeTime.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import runJest from '../runJest';
9+
10+
describe.each(['modern', 'legacy'])(
11+
'%s implementation of fake timers',
12+
implementation => {
13+
it('should be possible to use from config', () => {
14+
const result = runJest(`fake-time/${implementation}/from-config`);
15+
expect(result.exitCode).toBe(0);
16+
});
17+
18+
it('should be possible to use from jest-object', () => {
19+
const result = runJest(`fake-time/${implementation}/from-jest-object`);
20+
expect(result.exitCode).toBe(0);
21+
});
22+
},
23+
);

e2e/fake-promises/immediate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"jest": {
3-
"timers": "fake",
3+
"timers": "legacy",
44
"setupFiles": [
55
"<rootDir>/fake-promises"
66
],
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
test('fake timers', () => {
11+
expect(() => jest.setSystemTime(0)).toThrow(
12+
'setSystemTime is not available when not using modern timers',
13+
);
14+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"jest": {
3+
"timers": "legacy",
4+
"testEnvironment": "node"
5+
}
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
test('fake timers', () => {
11+
jest.useFakeTimers('legacy');
12+
13+
expect(() => jest.setSystemTime(0)).toThrow(
14+
'setSystemTime is not available when not using modern timers',
15+
);
16+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
test('fake timers', () => {
11+
jest.setSystemTime(0);
12+
13+
expect(Date.now()).toBe(0);
14+
15+
jest.setSystemTime(1000);
16+
17+
expect(Date.now()).toBe(1000);
18+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"jest": {
3+
"timers": "fake",
4+
"testEnvironment": "node"
5+
}
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
test('fake timers', () => {
11+
jest.useFakeTimers();
12+
13+
jest.setSystemTime(0);
14+
15+
expect(Date.now()).toBe(0);
16+
17+
jest.setSystemTime(1000);
18+
19+
expect(Date.now()).toBe(1000);
20+
});

0 commit comments

Comments
 (0)