I have an Angular CLI project with a NgModule
located outside of the /src
folder (eventually this NgModule will be packaged as a npm module but for now I'm just leaving it outside of /src
).
I'm trying to write unit tests for this NgModule but ng test
doesn't seem to pick up .spec.ts
files outside of the /src
folder.
I have tried altering the path in /src/test.ts
:
// Original
const context = require.context('./', true, /\.spec\.ts$/);
// Does not work
const context = require.context('../', true, /\.spec\.ts$/);
// Does not work
const context = require.context('/absolute/path/to/ngmodule', true, /\.spec\.ts$/);
But I get an error: Module build failed: Error: /absolute/path/to/file.spec.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
I have also tried adding the path to my NgModule in the include
property of tsconfig.spec.json
:
"include": [
"../my-ng-module/**/*.spec.ts", // Added this
"**/*.spec.ts",
"**/*.d.ts"
]
But no success. Any ideas?
tests.ts
, I havn't seen documentation around this anywhere. Thanks a lot for posting – Topside