Angular 因果报应不存在';找不到自定义类型

Angular 因果报应不存在';找不到自定义类型,angular,karma-jasmine,Angular,Karma Jasmine,我正在尝试为使用第三个JS库的组件设置测试。这个库有一些类型,在项目中,场景工作得很顺利。当我尝试运行标准替补因果报应时,它确实会触发一个错误: 未定义键入\u名称 我的项目结构(简化)如下: package.json angular.json karma.conf.js all tsconfig files typings/ *typing_name*.d.ts app/ - components/ - map/ map.componen

我正在尝试为使用第三个JS库的组件设置测试。这个库有一些类型,在项目中,场景工作得很顺利。当我尝试运行标准替补因果报应时,它确实会触发一个错误:

未定义键入\u名称

我的项目结构(简化)如下:

package.json
angular.json
karma.conf.js
all tsconfig files
typings/
    *typing_name*.d.ts
app/
    - components/
        - map/
            map.component.ts
            ...
            map.component.spec.ts
...
import { Something, SomethingElse, AnotherThing, ...} from 'my-custom-typing';
我添加了我的打字,如下所示:

ts.config.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "es2015",
    "target": "es6",
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "app/test.ts",
    "app/polyfills.ts"
  ],
  "include": [
    "typings/*.d.ts"
  ]
}
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist",
    "skipLibCheck": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "typings/*.d.ts",
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "jszip": [
        "node_modules/jszip/dist/jszip.min.js"
      ]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
tsconfig.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "es2015",
    "target": "es6",
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "app/test.ts",
    "app/polyfills.ts"
  ],
  "include": [
    "typings/*.d.ts"
  ]
}
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist",
    "skipLibCheck": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "typings/*.d.ts",
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "jszip": [
        "node_modules/jszip/dist/jszip.min.js"
      ]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
map.component.ts
中,我使用如下定义:

package.json
angular.json
karma.conf.js
all tsconfig files
typings/
    *typing_name*.d.ts
app/
    - components/
        - map/
            map.component.ts
            ...
            map.component.spec.ts
...
import { Something, SomethingElse, AnotherThing, ...} from 'my-custom-typing';
测试,因为是非常基本的,它只是这样:

describe('NngMapComponent', () => {
    let component: NngMapComponent;
    let fixture: ComponentFixture<NngMapComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            providers: [ToastrService, TranslationService, DataService, ShareService],
            imports: [
                HttpClientModule,
                ToastrModule.forRoot({
                    preventDuplicates: true
                }),
            ],
            declarations: [NngMapComponent]
        })
            .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(NngMapComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    fit('should create', () => {
        expect(component).toBeTruthy();
    });
});
description('NngMapComponent',()=>{
let组件:NngMapComponent;
let夹具:组件夹具;
beforeach(异步(()=>{
TestBed.configureTestingModule({
提供者:[ToastrService、TranslationService、DataService、ShareService],
进口:[
HttpClientModule,
ToastrModule.forRoot({
防止重复:正确
}),
],
声明:[NngMapComponent]
})
.compileComponents();
}));
在每个之前(()=>{
fixture=TestBed.createComponent(NngMapComponent);
组件=fixture.componentInstance;
fixture.detectChanges();
});
拟合('应创建',()=>{
expect(component.toBeTruthy();
});
});
运行测试将导致以下错误:

ReferenceError:未定义键入\u名称


我缺少什么?

我想您需要在
tsconfig.spec.json
中指定
typeroot

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "es2015",
    "target": "es6",
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ],
     "typeRoots": [
      "typings/*.d.ts", // this right here
    ],
  },
  "files": [
    "app/test.ts",
    "app/polyfills.ts"
  ],
  "include": [
    // "typings/*.d.ts" => Remove this, I don't think it's needed.
  ]
}

试试看。我担心
类型
类型根
属性可能会冲突,但您可以进行修补。

您认为是否必须将该文件添加到
karma.conf.js
中的
文件
数组中?完成,仍然没有任何内容。