为什么有时我会得到“不是已知元素”警告?
我有一项使用业力和茉莉花测试的服务。
title.service.spec
import { TestBed } from '@angular/core/testing';
import { UserPanelComponent } from '../layout/user-panel/user-panel.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { TitleService } from './title.service';
describe('TitleService', () => {
beforeEach(() => TestBed.configureTestingModule({
declarations: [ UserPanelComponent ],
imports: [ MatExpansionModule ],
}));
it('should be created', () => {
const service: TitleService = TestBed.get(TitleService);
expect(service).toBeTruthy();
});
});
title.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TitleService {
private Value;
constructor() {
this.Value = 'shiny beautiful string';
}
setValue(val) {
this.Value = val;
}
getValue() {
return this.Value ;
}
}
i运行测试,一切都很好。输出:
TitleService
√ should be created
我进行了另一项测试,我得到了:
TitleService
√ should be created
WARN LOG: ''mat-expansion-panel' is not a known element:
1. If 'mat-expansion-panel' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-expansion-panel' is not a known element:
1. If 'mat-expansion-panel' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN LOG: ''mat-expansion-panel-header' is not a known element:
1. If 'mat-expansion-panel-header' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-expansion-panel-header' is not a known element:
1. If 'mat-expansion-panel-header' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN LOG: ''mat-panel-description' is not a known element:
1. If 'mat-panel-description' is an Angular component, then verify that it is part of this module.
2. If 'mat-panel-description' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-panel-description' is not a known element:
1. If 'mat-panel-description' is an Angular component, then verify that it is part of this module.
2. If 'mat-panel-description' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
因此,总而言之,在测试时并非每次都会出现警告。为什么?如何永久摆脱它们?
I have a service which I want to test using Karma and Jasmine.
title.service.spec
import { TestBed } from '@angular/core/testing';
import { UserPanelComponent } from '../layout/user-panel/user-panel.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { TitleService } from './title.service';
describe('TitleService', () => {
beforeEach(() => TestBed.configureTestingModule({
declarations: [ UserPanelComponent ],
imports: [ MatExpansionModule ],
}));
it('should be created', () => {
const service: TitleService = TestBed.get(TitleService);
expect(service).toBeTruthy();
});
});
title.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TitleService {
private Value;
constructor() {
this.Value = 'shiny beautiful string';
}
setValue(val) {
this.Value = val;
}
getValue() {
return this.Value ;
}
}
I run tests and everything is fine. The output:
TitleService
√ should be created
I do another testing and I get this:
TitleService
√ should be created
WARN LOG: ''mat-expansion-panel' is not a known element:
1. If 'mat-expansion-panel' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-expansion-panel' is not a known element:
1. If 'mat-expansion-panel' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN LOG: ''mat-expansion-panel-header' is not a known element:
1. If 'mat-expansion-panel-header' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-expansion-panel-header' is not a known element:
1. If 'mat-expansion-panel-header' is an Angular component, then verify that it is part of this module.
2. If 'mat-expansion-panel-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN LOG: ''mat-panel-description' is not a known element:
1. If 'mat-panel-description' is an Angular component, then verify that it is part of this module.
2. If 'mat-panel-description' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
WARN: ''mat-panel-description' is not a known element:
1. If 'mat-panel-description' is an Angular component, then verify that it is part of this module.
2. If 'mat-panel-description' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
So to sum up, warnings don't appear every time when testing. Why? How to get rid of them permanently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论