|
| 1 | +require('../../../../dist/bin/packages/zone.js/npm_package/bundles/zone.umd.js'); |
| 2 | +require('../../../../dist/bin/packages/zone.js/npm_package/bundles/zone-testing.umd.js'); |
| 3 | + |
| 4 | +// Apply the Vitest patch (i.e. `patchVitest`). |
| 5 | +require('../../../../dist/bin/packages/zone.js/npm_package/bundles/vitest-patch.umd.js'); |
| 6 | + |
| 7 | +const {fakeAsync, tick} = Zone[Zone.__symbol__('fakeAsyncTest')]; |
| 8 | + |
| 9 | +describe('patchVitest `describe`', () => { |
| 10 | + test('verify that the patch is installed', () => { |
| 11 | + expect(globalThis['vitest']['__zone_patch__']).toBe(true); |
| 12 | + }); |
| 13 | + |
| 14 | + // Expect `beforeEach` to be patched and working with `fakeAsync`. |
| 15 | + beforeEach(fakeAsync(() => { |
| 16 | + expect(createAsyncTesterFlag()).toBe(true); |
| 17 | + })); |
| 18 | + |
| 19 | + // Expect `afterEach` to be patched and working with `fakeAsync`. |
| 20 | + afterEach(fakeAsync(() => { |
| 21 | + expect(createAsyncTesterFlag()).toBe(true); |
| 22 | + })); |
| 23 | + |
| 24 | + // Expect `beforeAll` to be patched and working with `fakeAsync`. |
| 25 | + beforeAll(fakeAsync(() => { |
| 26 | + expect(createAsyncTesterFlag()).toBe(true); |
| 27 | + })); |
| 28 | + |
| 29 | + // Expect `afterAll` to be patched and working with `fakeAsync`. |
| 30 | + afterAll(fakeAsync(() => { |
| 31 | + expect(createAsyncTesterFlag()).toBe(true); |
| 32 | + })); |
| 33 | + |
| 34 | + it('expect `it` to be patched and working with `fakeAsync`', fakeAsync(() => { |
| 35 | + expect(createAsyncTesterFlag()).toBe(true); |
| 36 | + })); |
| 37 | + |
| 38 | + test('expect `it` to be patched and working with `fakeAsync`', fakeAsync(() => { |
| 39 | + expect(createAsyncTesterFlag()).toBe(true); |
| 40 | + })); |
| 41 | +}); |
| 42 | + |
| 43 | +suite('patchVitest `suite`', () => { |
| 44 | + it('should work with a patched `suite`', fakeAsync(() => { |
| 45 | + expect(createAsyncTesterFlag()).toBe(true); |
| 46 | + })); |
| 47 | +}); |
| 48 | + |
| 49 | +function createAsyncTesterFlag() { |
| 50 | + let flag = false; |
| 51 | + setTimeout(() => { |
| 52 | + flag = true; |
| 53 | + }, 100); |
| 54 | + |
| 55 | + tick(110); |
| 56 | + |
| 57 | + return flag; |
| 58 | +} |
0 commit comments