I'm using jest framework to unit-test my Angular application. I'm having trouble in test.ts file with the zone.js I think.
I'm getting the error stack trace
TypeError: Cannot read property 'prototype' of undefined
3 | import { getTestBed } from '@angular/core/testing';
4 | import 'zone.js/dist/zone-testing';
> 5 | import {
| ^
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
at __extends (node_modules/zone.js/dist/zone-testing.js:394:73)
at node_modules/zone.js/dist/zone-testing.js:530:9
at node_modules/zone.js/dist/zone-testing.js:619:7
at node_modules/zone.js/dist/zone-testing.js:620:3
at Object.<anonymous>.NEWLINE (node_modules/zone.js/dist/zone-testing.js:9:65)
at Object.<anonymous> (node_modules/zone.js/dist/zone-testing.js:12:2)
at Object.<anonymous> (src/test.ts:5:1
I'm looking for a way to fix this issue with the minimum changes in code.
I have already tried to adapt to the solutions given in
https://github.com/AlexanderZaytsev/react-native-i18n/issues/233
and
Jest: TypeError: Cannot read property of undefined without any luck.
Also, I have tried the docs, but it does not specify anything related to this or I have missed it.
This is my test.ts file.
import { getTestBed } from '@angular/core/testing';
import 'zone.js/dist/zone-testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
I have used the compilerOptions,
"esModuleInterop": true,
"module": "es2015",
As I have said, I'm looking for a way to fix this with minimum code change. Any help is appreciated.