Edit2:更具体的说,使用像Material这样的东西很好。但是,侧Nav与下面的设置不太协调。
编辑:我做了更多的测试,发现这与角度材料特别相关,因为没有它这些错误是不会发生的。我还是不知道怎么修好它。
我正在尝试为一个新组件设置一些基本测试,但是我总是不断地遇到错误。具体而言,在项目中添加“角/材料”之后。当前的错误是:
Error: Found the synthetic listener @transform.start. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.对我来说就像一条红鲱鱼。
这是规范:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { MatSidenavModule } from '@angular/material/sidenav';
import { AngularNavigationComponent } from './angular-navigation.component';
describe('AngularNavigationComponent', () => {
let component: AngularNavigationComponent;
let fixture: ComponentFixture<AngularNavigationComponent>;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [AngularNavigationComponent],
imports: [RouterTestingModule, MatSidenavModule]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AngularNavigationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});这是组件
import { Component, OnInit } from '@angular/core';
import { MatSidenavModule } from '@angular/material/sidenav';
import { RouterLink } from '@angular/router';
@Component({
selector: 'mysupercustomcat-navigation',
templateUrl: './angular-navigation.component.html',
styleUrls: ['./angular-navigation.component.scss']
})
export class AngularNavigationComponent implements OnInit {
constructor() {}
ngOnInit() {}
}有人能告诉我我做错了什么吗?也许还可以解释一下Testbed配置区域中的声明和导入吗?
编辑:如果这重要的话,这是一个混合应用。
发布于 2018-02-23 20:03:56
为了避免这样的错误,我增加了两个关键部分:
import { NO_ERRORS_SCHEMA } from '@angular/core';在页面顶部添加,并:
schemas: [NO_ERRORS_SCHEMA],在与声明相同的级别添加。
这是干什么用的?这告诉我们不要在未知的元素或属性上出错。现在,这可以用于这个用例,因为我对集成测试不太感兴趣。我相信这可能会在这件事上引起问题。
我对单元测试感兴趣,忽略模板属性对我来说很好。加上这个,我就可以达到这个水平了。
这是我目前所能得到的全部答案。
https://stackoverflow.com/questions/48913655
复制相似问题