diff --git a/integration_tests/__tests__/timer-useRealTimers-test.js b/integration_tests/__tests__/timer-useRealTimers-test.js new file mode 100644 index 000000000000..9116f0d5e603 --- /dev/null +++ b/integration_tests/__tests__/timer-useRealTimers-test.js @@ -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); +}); diff --git a/integration_tests/timer-useRealTimers/__tests__/use_real_timers.test.js b/integration_tests/timer-useRealTimers/__tests__/use_real_timers.test.js new file mode 100644 index 000000000000..e59f6f45c958 --- /dev/null +++ b/integration_tests/timer-useRealTimers/__tests__/use_real_timers.test.js @@ -0,0 +1,5 @@ +jest.useRealTimers(); + +test('bar', () => { + jest.runAllTimers(); +}); diff --git a/integration_tests/timer-useRealTimers/package.json b/integration_tests/timer-useRealTimers/package.json new file mode 100644 index 000000000000..1cb610cba16b --- /dev/null +++ b/integration_tests/timer-useRealTimers/package.json @@ -0,0 +1,6 @@ +{ + "jest": { + "testEnvironment": "node", + "timers": "fake" + } +} diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index 525a965044e5..32701ea4bbca 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -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(); @@ -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(); + } } });