我试图在Angular中执行我的第一个测试,我想测试一个服务,但是当我运行ng test
时,它在我在tsconf中定义的所有相对导入中给了我一个错误。Json,例如
"@interceptors/*": [
"./src/app/interceptors/*"
],
给我这个错误
ERROR in src/app/app.module.ts:17:44 - error TS2307: Cannot find module '@interceptors/allhttprequests.interceptor' or its corresponding type declarations.
在Angular应用中,通常有多个tsconfig
文件:
-
tsconfig.json
-
tsconfig.app.json
-
tsconfig.spec.json
通常,tsconfig.app.json
和tsconfig.spec.json
文件扩展tsconfig.json
。
tsconfig.app.json
用于正常构建。tsconfig.spec.json
用于测试构建。(更多的信息。)
如果正常的ng build
没有给出关于您的路径的任何错误,我猜您只将@interceptors/*
路径添加到tsconfig.app.json
,而不是tsconfig.spec.json
。
我不是100%确定以下内容:
如果您在tsconfig.json
中指定了paths
,但在tsconfig.spec.json
中也指定了paths
,则后者中的paths
可能会覆盖tsconfig.json
中的paths
。