Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make useRealTimers play well with timers: fake #3858

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions integration_tests/__tests__/timer-useRealTimers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

const runJest = require('../runJest');

test('useRealTimers cancels "timers": "fake" for whole test file', () => {
const result = runJest('timer-useRealTimers');
expect(result.stdout).toMatch('API is not mocked with fake timers.');
expect(result.status).toBe(0);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jest.useRealTimers();

test('bar', () => {
jest.runAllTimers();
});
6 changes: 6 additions & 0 deletions integration_tests/timer-useRealTimers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"testEnvironment": "node",
"timers": "fake"
}
}
10 changes: 7 additions & 3 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function jasmine2(
environment.global.describe.skip = environment.global.xdescribe;
environment.global.describe.only = environment.global.fdescribe;

if (config.timers === 'fake') {
environment.fakeTimers.useFakeTimers();
}

env.beforeEach(() => {
if (config.resetModules) {
runtime.resetModules();
Expand All @@ -61,10 +65,10 @@ function jasmine2(

if (config.resetMocks) {
runtime.resetAllMocks();
}

if (config.timers === 'fake') {
environment.fakeTimers.useFakeTimers();
if (config.timers === 'fake') {
environment.fakeTimers.useFakeTimers();
}
}
});

Expand Down