我有一个 Angular CLI 项目,它NgModule
位于/src
文件夹之外(最终这个 NgModule 将被打包为一个 npm 模块,但现在我只是把它放在外面/src
)。
我正在尝试为此 NgModule 编写单元测试,但ng test
似乎没有拾取.spec.ts
文件夹之外的/src
文件。
我试过改变路径/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$/);
但我收到一个错误: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.
我还尝试在以下include
属性中添加我的 NgModule 的路径tsconfig.spec.json
:
"include": [
"../my-ng-module/**/*.spec.ts", // Added this
"**/*.spec.ts",
"**/*.d.ts"
]
但没有成功。有任何想法吗?