nativescript-angular: NG11 Test failure : Error: zone-testing.js is needed for the async() test helper but could not be found.
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 7.1.0
- Cross-platform modules: 7.1.0
- Android Runtime:
- iOS Runtime: 7.1.0
- Plugin(s):
- NativeScript-Angular: 11.0.0
- Angular: 11.0
Describe the bug
ns test seem to be broken on a fresh nativescript angular project with “Error: zone-testing.js is needed for the async() test helper but could not be found.”
To Reproduce
I’ve created a project using :
ns create --ng --id sample-ng sample-ng
Then, i’ve followed this documentation https://docs.nativescript.org/angular/tooling/testing/testing
The documentation has not been updated, some path are incorrect in setup.ts. My setup.ts
import '@nativescript/zone-js/testing.jasmine';
import {nsTestBedInit} from '@nativescript/angular/testing';
nsTestBedInit();
Then execute :
ns test ios
The result :
NativeScript / 14.2 (14.2; iPhone) Renderer E2E executes events inside NgZone when listen is called outside NgZone FAILED
Error: zone-testing.js is needed for the async() test helper but could not be found.
Please make sure that your environment includes zone.js/dist/zone-testing.js
error properties: Object({ originalStack: 'Error: zone-testing.js is needed for the async() test helper but could not be found.
Please make sure that your environment includes zone.js/dist/zone-testing.js
at new ZoneAwareError (file:///app/vendor.js:152354:33)
at resetFakeAsyncZone (file:///app/vendor.js:77146:11)
at UserContext.<anonymous> (file:///app/vendor.js:79298:9)
at ZoneQueueRunner.attempt (eval at runTest (file:///app/vendor.js:149440:17), <anonymous>:7063:44)
at ZoneQueueRunner.QueueRunner.run (eval at runTest (file:///app/vendor.js:149440:17), <anonymous>:7104:25)
at runNext (eval at runTest (file:///app/vendor.js:149440:17), <anonymous>:7023:18)
at next (eval at runTest (file:///app/vendor.js:149440:17), <anonymous>:7030:11)
at eval (eval at runTest (file:///app/vendor.js:149440:17), <anonymous>:6924:9)
at ZoneDelegate.push.../node_modules/@nativescript/zone-js/zone-nativescript.js.ZoneDelegate.invokeTask (file:///app/vendor.js:151477:31)
...
Error: zone-testing.js is needed for the async() test helper but could not be found.
Please make sure that your environment includes zone.js/dist/zone-testing.js
at new ZoneAwareError (file:///app/vendor.js:152354:33)
at resetFakeAsyncZone (file:///app/vendor.js:77146:11)
at UserContext.<anonymous> (file:///app/vendor.js:79298:9)
at <Jasmine>
at ZoneDelegate.push.../node_modules/@nativescript/zone-js/zone-nativescript.js.ZoneDelegate.invokeTask (file:///app/vendor.js:151477:31)
at Zone.push.../node_modules/@nativescript/zone-js/zone-nativescript.js.Zone.runTask (file:///app/vendor.js:151244:47)
at drainMicroTaskQueue (file:///app/vendor.js:151651:35)
zone-testing.js is needed for the async() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone-testing.js thrown
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 17
- Comments: 19 (1 by maintainers)
Not sure if it will be useful in you case but I just fixed a similar error by changing the import order of
zone-testingin mysrc/test.tsfile :Actually thanks for that hint… never thought it could be the order of imports… Just as a small addition to this.
The import of zone-testing has to be the very first of all imports. Line 1 -
import 'zone.js/dist/zone-testing';Add this to
setup.Jest.tsfile in the root folder:it worked, but is there any explanation for this?
Not sure if this helps, but I was able to get my NS7/NG11 app to run Jasmine/Karma unit tests. I had to do some serious package testing (dependency validation) to see what works, but all good.
package.json
karma.config.js
setup.ts (customized and placed in the root of the ‘tests’ folder):
feedback.component.spec.ts (a spec file with a few tests)