【发布时间】:2019-05-03 09:02:04
【问题描述】:
我的项目在我运行时运行良好
服务
但是当我使用运行一个简单的“tobeTruthy()”测试用例时它显示了多个错误
ng 测试
HTML 文件
<ngx-spinner bdColor="rgba(51,51,51,0.8)" size="medium" color="#fff" type="ball-scale-multiple">
<p style="font-size: 20px; color: white">Loading...</p>
</ngx-spinner>
<div *ngIf="isAuthenticated" class="container-fluid">
<app-app-menu></app-app-menu>
<router-outlet></router-outlet>
</div>
app.component.ts
import { Router } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { map } from 'rxjs/operators';
import { AppState } from './app.reducer';
import { UserState } from './core/store/core.state';
import * as CoreActions from './core/store/core.actions';
import { Globals } from './shared/globals';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
datetime = new Date();
title = 'curemd-x';
isAuthenticated = false;
constructor(private store: Store<AppState>, private router: Router,
private globals: Globals) {}
...
...
业力错误
"Failed: Template parse errors:
'ngx-spinner' is not a known element:
1. If 'ngx-spinner' is an Angular component, then verify that it is part of this module.
2. If 'ngx-spinner' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<ngx-spinner bdColor="rgba(51,51,51,0.8)" size="medium" color="#fff" type="ball-scale-multiple">
<p"): ng:///DynamicTestModule/AppComponent.html@0:0
'app-app-menu' is not a known element:
1. If 'app-app-menu' is an Angular component, then verify that it is part of this module.
2. If 'app-app-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</ngx-spinner>
<div *ngIf="isAuthenticated" class="container-fluid">
[ERROR ->]<app-app-menu></app-app-menu>
<router-outlet></router-outlet>
</div>
"): ng:///DynamicTestModule/AppComponent.html@4:2
我也尝试添加“CUSTOM_ELEMENTS_SCHEMA”,但没有成功。
“app-app-menu”是核心模块中的一个组件,核心模块是在app.module中导入的
app.module.ts
declarations: [
AppComponent,
FirstOrDefaultPipe
],
imports: [
RouterModule,
BrowserModule,
HttpClientModule,
PatientModule,
StoreModule.forRoot(AppReducers),
EffectsModule.forRoot([]),
CoreModule,
NgxSpinnerModule,
BrowserAnimationsModule,
DropDownsModule
],
providers: [Globals],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
如何为应用模块实例运行成功的测试用例?
【问题讨论】:
-
您可以尝试运行
npm run prod-build-staging --verbose。也许这会给你更多的细节
标签: angular unit-testing karma-runner