Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/zone.js/lib/zone-spec/async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export function patchAsyncTest(Zone: ZoneType): void {
throw e;
};
}
runInTestZone(fn, this, done, (err: any) => {
runInTestZone(fn, this, undefined, done, (err: any) => {
if (typeof err === 'string') {
return done.fail(new Error(err));
} else {
Expand All @@ -261,16 +261,17 @@ export function patchAsyncTest(Zone: ZoneType): void {
// is finished. This will be correctly consumed by the Mocha framework with
// it('...', async(myFn)); or can be used in a custom framework.
// Not using an arrow function to preserve context passed from call site
return function (this: unknown) {
return function (this: unknown, ...args: unknown[]) {
return new Promise<void>((finishCallback, failCallback) => {
runInTestZone(fn, this, finishCallback, failCallback);
runInTestZone(fn, this, args, finishCallback, failCallback);
});
};
};

function runInTestZone(
fn: Function,
context: any,
applyArgs: unknown[] | undefined,
finishCallback: Function,
failCallback: Function,
) {
Expand Down Expand Up @@ -329,7 +330,7 @@ export function patchAsyncTest(Zone: ZoneType): void {
proxyZoneSpec.setDelegate(testZoneSpec);
(testZoneSpec as any).patchPromiseForTest();
});
return Zone.current.runGuarded(fn, context);
return Zone.current.runGuarded(fn, context, applyArgs);
}
});
}
14 changes: 14 additions & 0 deletions packages/zone.js/test/jest/jest.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const waitForAsync = Zone[Zone.__symbol__('asyncTest')];

function assertInsideProxyZone() {
expect(Zone.current.name).toEqual('ProxyZone');
}
Expand Down Expand Up @@ -43,6 +45,18 @@ describe('test', () => {
test.each([[]])('test.each', () => {
assertInsideProxyZone();
});

test.each([
['1', 1],
['2', 2],
])(
'Test.each ["%s", %s]',
waitForAsync((p1, p2) => {
expect(typeof p1).toEqual('string');
expect(typeof p2).toEqual('number');
expect(p1).toEqual('' + p2);
}),
);
});

it('it', () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/zone.js/test/vitest/vitest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require('../../../../dist/bin/packages/zone.js/npm_package/bundles/zone-testing.

import {expect, test, describe, beforeEach} from 'vitest';

const {tick, withProxyZone, fakeAsync} = Zone[Zone.__symbol__('fakeAsyncTest')];
const {tick, withProxyZone, fakeAsync, asyncTest} = Zone[Zone.__symbol__('fakeAsyncTest')];
const waitForAsync = Zone[Zone.__symbol__('asyncTest')];

describe('proxy zone behavior', () => {
const spec = new Zone['ProxyZoneSpec']();
Expand Down Expand Up @@ -85,6 +86,16 @@ test(
),
);

test.each([[1, 2]])(
'it.each',
withProxyZone(
waitForAsync((arg1, arg2) => {
expect(arg1).toBe(1);
expect(arg2).toBe(2);
}),
),
);

describe('can use withProxyZone and beforeEach', () => {
let forkedZone;
beforeEach(
Expand Down