From 1d39aa75dbdb192386555c703a37777091b5aaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 1 Apr 2017 17:28:32 +0200 Subject: [PATCH 1/2] Fix done.fail context issue --- .../jest-jasmine2/src/__tests__/queueRunner-test.js | 13 +++++++++++++ packages/jest-jasmine2/src/queueRunner.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/jest-jasmine2/src/__tests__/queueRunner-test.js b/packages/jest-jasmine2/src/__tests__/queueRunner-test.js index bbda173bc72a..dbedb86e239f 100644 --- a/packages/jest-jasmine2/src/__tests__/queueRunner-test.js +++ b/packages/jest-jasmine2/src/__tests__/queueRunner-test.js @@ -117,4 +117,17 @@ describe('queueRunner', () => { ); expect(fnTwo).toHaveBeenCalled(); }); + + it('calls `fail` with arguments', async () => { + const failFn = jest.fn(next => next.fail('miserably', 'failed')); + const options = { + clearTimeout, + fail: jest.fn(), + queueableFns: [{fn: failFn}], + setTimeout, + }; + await queueRunner(options); + + expect(options.fail).toHaveBeenCalledWith('miserably', 'failed'); + }); }); diff --git a/packages/jest-jasmine2/src/queueRunner.js b/packages/jest-jasmine2/src/queueRunner.js index 11770f81f9ec..486e7a9162b5 100644 --- a/packages/jest-jasmine2/src/queueRunner.js +++ b/packages/jest-jasmine2/src/queueRunner.js @@ -31,7 +31,7 @@ function queueRunner(options: Options) { const mapper = ({fn, timeout}) => { const promise = new Promise(resolve => { const next = once(resolve); - next.fail = () => { + next.fail = function() { options.fail.apply(null, arguments); resolve(); }; From 36991a03bb2a003416db9b1f8e89d60bca5dd85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 2 Apr 2017 11:01:57 +0200 Subject: [PATCH 2/2] Use concat instead of spread to fix node 4 --- packages/jest-jasmine2/src/treeProcessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-jasmine2/src/treeProcessor.js b/packages/jest-jasmine2/src/treeProcessor.js index 036ba0b43e66..e009bccd00cd 100644 --- a/packages/jest-jasmine2/src/treeProcessor.js +++ b/packages/jest-jasmine2/src/treeProcessor.js @@ -74,7 +74,7 @@ function treeProcessor(options: Options) { throw new Error('`node.children` is not defined.'); } const children = node.children.map(child => executeNode(child, enabled)); - return [...node.beforeAllFns, ...children, ...node.afterAllFns]; + return node.beforeAllFns.concat(children).concat(node.afterAllFns); } }