Skip to content

Commit

Permalink
fix: should handle each args with 1D array case
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Mar 12, 2020
1 parent d6bc119 commit 849c006
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions example/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/zone-patch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 849c006

Please sign in to comment.