1

Hello! I'm working on a quite big Angular 13 application that has unit tests for almost all components/services/pipes/etc. After a long time, we decided to split the application into Angular modules and implement lazy loading. It's already working, but after fixing all the imports in the unit tests we still have one unit test failing. It's always the first one. The tested component is random. For now, I observed that the failing unit tests were from components/pipes from SharedModule and CoreModule which are imported not lazily in the app module, but probably I just didn't run it enough times to get components from other modules as well.

Error in Karma

I don't know how to debug it. I found this question from StackOverflow, but I don't know how to apply it in ng test.

This is my test.ts file:

import "zone.js/testing";
import { getTestBed } from "@angular/core/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";

declare const require: any;

getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
const context = require.context("./", true, /\.spec\.ts$/);
context.keys().map(context);

This is my tsconfig.json that is used for test:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": ["jasmine", "node"],
    "target": "es5"
  },
  "files": ["src/test.ts", "src/polyfills.ts"],
  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
Szwajowy
  • 15
  • 4

1 Answers1

0

I found the reason. The problem was that I was in did having circular dependency. I had some variables in the app.module which were imported by a shared module which is also imported in app.module.

For the debuging information I turned on the "Stop at exception" function in Chrome Dev Tools

Szwajowy
  • 15
  • 4