From 849c0066772de470ee699e0f30ffd260d6a78d05 Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Thu, 12 Mar 2020 19:42:44 +0900 Subject: [PATCH] fix: should handle each args with 1D array case --- example/src/app/app.component.spec.ts | 9 +++++++++ src/zone-patch/index.js | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/example/src/app/app.component.spec.ts b/example/src/app/app.component.spec.ts index 46903c06ca..c2afc8410e 100644 --- a/example/src/app/app.component.spec.ts +++ b/example/src/app/app.component.spec.ts @@ -94,6 +94,15 @@ describe('AppComponent', () => { expect(arg2).toBe(2); }); + it.each([2])('it.each with 1D array', arg1 => { + expect(arg1).toBe(2); + }); + + (it.each([2]) as any)('it.each with 1D array and done', (arg1, done) => { + expect(arg1).toBe(2); + done(); + }); + (it.each([[1, 2]]) as any)('it.each with done', (arg1, arg2, done) => { expect(arg1).toBe(1); expect(arg2).toBe(2); diff --git a/src/zone-patch/index.js b/src/zone-patch/index.js index 25a0d4a39a..e5f6bfd0b7 100644 --- a/src/zone-patch/index.js +++ b/src/zone-patch/index.js @@ -109,6 +109,18 @@ const bindTest = originalJestFn => function(...eachArgs) { return function(...args) { const testBody = args[1]; + if ( + testBody.length > 0 && + Array.isArray(eachArgs) && + eachArgs.length > 0 && + eachArgs[0].length > 0 + ) { + // check whether eachArgs is a 1D array + if (!Array.isArray(eachArgs[0][0])) { + // transfer eachArgs from 1D to 2D array + eachArgs = eachArgs.map(row => row.map(a => [a])); + } + } args[1] = wrapTestInZone(args[1], ...eachArgs); if (testBody.length > 0 || (eachArgs.length > 0 && eachArgs[0].length > 0)) { eachArgs.forEach(row => {