diff --git a/Libraries/Interaction/__tests__/InteractionManager-test.js b/Libraries/Interaction/__tests__/InteractionManager-test.js index 4e11d7f32..e55fe7104 100644 --- a/Libraries/Interaction/__tests__/InteractionManager-test.js +++ b/Libraries/Interaction/__tests__/InteractionManager-test.js @@ -163,6 +163,7 @@ describe('promise tasks', () => { } beforeEach(() => { jest.resetModules(); + jest.useFakeTimers(); InteractionManager = require('InteractionManager'); BatchedBridge = require('BatchedBridge'); sequenceId = 0; @@ -255,7 +256,9 @@ describe('promise tasks', () => { expectToBeCalledOnce(task2); }); - const bigAsyncTest = () => { + const bigAsyncTest = (resolve) => { + jest.useRealTimers(); + const task1 = createSequenceTask(1); const task2 = jest.fn(() => { expect(++sequenceId).toBe(2); @@ -281,27 +284,25 @@ describe('promise tasks', () => { InteractionManager.runAfterInteractions({gen: task2, name: 'gen2'}); InteractionManager.runAfterInteractions(task6); - jest.runAllTimers(); - // 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(); + setTimeout(() => { + expectToBeCalledOnce(task1); + expectToBeCalledOnce(task2); + expectToBeCalledOnce(task3); + expectToBeCalledOnce(task4); + expectToBeCalledOnce(task5); + expectToBeCalledOnce(task6); - expectToBeCalledOnce(task1); - expectToBeCalledOnce(task2); - expectToBeCalledOnce(task3); - expectToBeCalledOnce(task4); - expectToBeCalledOnce(task5); - expectToBeCalledOnce(task6); + resolve(); + }, 100); }; it('resolves async tasks recusively before other queued tasks', () => { - bigAsyncTest(); + return new Promise(bigAsyncTest); }); it('should also work with a deadline', () => { InteractionManager.setDeadline(100); BatchedBridge.getEventLoopRunningTime.mockReturnValue(200); - bigAsyncTest(); + return new Promise(bigAsyncTest); }); }); diff --git a/Libraries/Interaction/__tests__/TaskQueue-test.js b/Libraries/Interaction/__tests__/TaskQueue-test.js index 717668a4b..c9c12100d 100644 --- a/Libraries/Interaction/__tests__/TaskQueue-test.js +++ b/Libraries/Interaction/__tests__/TaskQueue-test.js @@ -10,6 +10,8 @@ 'use strict'; +const Promise = require('promise'); + function expectToBeCalledOnce(fn) { expect(fn.mock.calls.length).toBe(1); } diff --git a/package.json b/package.json index aaddf911f..a2be95485 100644 --- a/package.json +++ b/package.json @@ -227,9 +227,9 @@ "eslint-plugin-flowtype": "^2.33.0", "eslint-plugin-react": "^7.0.1", "flow-bin": "^0.47.0", - "jest": "19.0.2", - "jest-repl": "19.0.2", - "jest-runtime": "^19.0.3", + "jest": "^20.0.4", + "jest-repl": "^20.0.4", + "jest-runtime": "^20.0.4", "mock-fs": "^4.3.0", "react": "16.0.0-alpha.12", "react-test-renderer": "16.0.0-alpha.12",