Move jest to version 20

Reviewed By: cpojer

Differential Revision: D5235642

fbshipit-source-id: eaeee1c5f67cf295fdc9798fb13bd5a83706af10
This commit is contained in:
Miguel Jiménez Esún 2017-06-14 12:44:05 -07:00 committed by Facebook Github Bot
parent 9250250364
commit c9a39b3bd3
3 changed files with 20 additions and 17 deletions

View File

@ -163,6 +163,7 @@ describe('promise tasks', () => {
} }
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
jest.useFakeTimers();
InteractionManager = require('InteractionManager'); InteractionManager = require('InteractionManager');
BatchedBridge = require('BatchedBridge'); BatchedBridge = require('BatchedBridge');
sequenceId = 0; sequenceId = 0;
@ -255,7 +256,9 @@ describe('promise tasks', () => {
expectToBeCalledOnce(task2); expectToBeCalledOnce(task2);
}); });
const bigAsyncTest = () => { const bigAsyncTest = (resolve) => {
jest.useRealTimers();
const task1 = createSequenceTask(1); const task1 = createSequenceTask(1);
const task2 = jest.fn(() => { const task2 = jest.fn(() => {
expect(++sequenceId).toBe(2); expect(++sequenceId).toBe(2);
@ -281,27 +284,25 @@ describe('promise tasks', () => {
InteractionManager.runAfterInteractions({gen: task2, name: 'gen2'}); InteractionManager.runAfterInteractions({gen: task2, name: 'gen2'});
InteractionManager.runAfterInteractions(task6); InteractionManager.runAfterInteractions(task6);
jest.runAllTimers(); setTimeout(() => {
// runAllTimers doesn't actually run all timers with nested timer functions
// inside Promises, so we have to call it extra times.
jest.runAllTimers();
jest.runAllTimers();
expectToBeCalledOnce(task1); expectToBeCalledOnce(task1);
expectToBeCalledOnce(task2); expectToBeCalledOnce(task2);
expectToBeCalledOnce(task3); expectToBeCalledOnce(task3);
expectToBeCalledOnce(task4); expectToBeCalledOnce(task4);
expectToBeCalledOnce(task5); expectToBeCalledOnce(task5);
expectToBeCalledOnce(task6); expectToBeCalledOnce(task6);
resolve();
}, 100);
}; };
it('resolves async tasks recusively before other queued tasks', () => { it('resolves async tasks recusively before other queued tasks', () => {
bigAsyncTest(); return new Promise(bigAsyncTest);
}); });
it('should also work with a deadline', () => { it('should also work with a deadline', () => {
InteractionManager.setDeadline(100); InteractionManager.setDeadline(100);
BatchedBridge.getEventLoopRunningTime.mockReturnValue(200); BatchedBridge.getEventLoopRunningTime.mockReturnValue(200);
bigAsyncTest(); return new Promise(bigAsyncTest);
}); });
}); });

View File

@ -10,6 +10,8 @@
'use strict'; 'use strict';
const Promise = require('promise');
function expectToBeCalledOnce(fn) { function expectToBeCalledOnce(fn) {
expect(fn.mock.calls.length).toBe(1); expect(fn.mock.calls.length).toBe(1);
} }

View File

@ -227,9 +227,9 @@
"eslint-plugin-flowtype": "^2.33.0", "eslint-plugin-flowtype": "^2.33.0",
"eslint-plugin-react": "^7.0.1", "eslint-plugin-react": "^7.0.1",
"flow-bin": "^0.47.0", "flow-bin": "^0.47.0",
"jest": "19.0.2", "jest": "^20.0.4",
"jest-repl": "19.0.2", "jest-repl": "^20.0.4",
"jest-runtime": "^19.0.3", "jest-runtime": "^20.0.4",
"mock-fs": "^4.3.0", "mock-fs": "^4.3.0",
"react": "16.0.0-alpha.12", "react": "16.0.0-alpha.12",
"react-test-renderer": "16.0.0-alpha.12", "react-test-renderer": "16.0.0-alpha.12",