NativeScript/nativescript-angular

Wrapping a spec in fakeAsync results in ProxyZone error on a new app

jpakulski opened this issue · 2 comments

Environment

  • CLI: 8.2.3
  • Cross-platform modules:
  • Android Runtime: N/A
  • iOS Runtime: 8.2.3
  • Plugin(s): See below
  • NativeScript-Angular: 13.0.3
  • Angular: 13.2.6

Describe the bug
Wrapping a spec in fakeAsync causes the following error in a newly generated app (despite the usual zone dependencies imported):
Error: Expected to be running in 'ProxyZone', but it was not found.

To Reproduce
create a new app: ns create --ng

initialise specs: ns test init (select jasmine)

run tests: ns test ios --device (tests pass)

wrap the example spec in fakeAsync add imports. The spec should now look like this:

import { fakeAsync } from '@angular/core/testing';

// A sample Jasmine test
describe("A suite", function() {
  it("contains spec with an expectation", fakeAsync(function() {
    expect(true).toBe(true);
  }));
});

Add zone and zone testing to the spec config file ./src/test.ts. The file should look like this:

import 'zone.js/dist/zone';
import '@nativescript/zone-js';
import 'zone.js/dist/zone-testing';
import { runTestApp } from '@nativescript/unit-test-runner';

declare let require: any;

runTestApp({
	runTests: () => {
		const tests = require.context('./', true, /\.spec\.ts$/);
		tests.keys().map(tests);
	},
});

Re-run tests: ns test ios --device . The tests now fail with the following error message:

NativeScript / 14.5 (14.5; iPhone) A suite contains spec with an expectation FAILED
	Error: Expected to be running in 'ProxyZone', but it was not found.
	    at Function.ProxyZoneSpec.assertPresent (file:///app/vendor.js:79382:15)
	    at UserContext.fakeAsyncFn (file:///app/vendor.js:81664:43)
	    at <Jasmine>
	    at timer (file:///app/vendor.js:85010:47)
	    at _ZoneDelegate.exports.modules../node_modules/zone.js/dist/zone.js._ZoneDelegate.invokeTask (file:///app/vendor.js:82325:35)

I tried to apply (to ./src/test.ts) a variety of patches/additional goodness, cleverly hidden in zone.js, various combinations of:

import '@nativescript/core/globals';
import '@nativescript/angular/polyfills';
import '@nativescript/zone-js/dist/pre-zone-polyfills';
import 'zone.js/dist/proxy';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/zone-legacy';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'zone.js/dist/zone-patch-rxjs-fake-async';

Thank You for Your help.

Expected behavior
Test should pass.

Thank You very much. All now passes.
It would be epic if that was the generated spec scaffold when angular is used.
Thank You again.