首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用茉莉花测试材料设计角元件

用茉莉花测试材料设计角元件
EN

Stack Overflow用户
提问于 2018-02-21 19:10:33
回答 1查看 1.1K关注 0票数 1

Edit2:更具体的说,使用像Material这样的东西很好。但是,侧Nav与下面的设置不太协调。

编辑:我做了更多的测试,发现这与角度材料特别相关,因为没有它这些错误是不会发生的。我还是不知道怎么修好它。

我正在尝试为一个新组件设置一些基本测试,但是我总是不断地遇到错误。具体而言,在项目中添加“角/材料”之后。当前的错误是:

代码语言:javascript
复制
Error: Found the synthetic listener @transform.start. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.

对我来说就像一条红鲱鱼。

这是规范:

代码语言:javascript
复制
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();
    });
});

这是组件

代码语言:javascript
复制
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配置区域中的声明和导入吗?

编辑:如果这重要的话,这是一个混合应用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-23 20:03:56

为了避免这样的错误,我增加了两个关键部分:

代码语言:javascript
复制
import { NO_ERRORS_SCHEMA } from '@angular/core';

在页面顶部添加,并:

代码语言:javascript
复制
schemas: [NO_ERRORS_SCHEMA],

在与声明相同的级别添加。

这是干什么用的?这告诉我们不要在未知的元素或属性上出错。现在,这可以用于这个用例,因为我对集成测试不太感兴趣。我相信这可能会在这件事上引起问题。

我对单元测试感兴趣,忽略模板属性对我来说很好。加上这个,我就可以达到这个水平了。

这是我目前所能得到的全部答案。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48913655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档