gpt4 book ai didi

javascript - 用 jasmine 测试 Material Design Angular 组件

转载 作者:行者123 更新时间:2023-11-28 20:27:37 25 4
gpt4 key购买 nike

Edit2:更具体地说,使用 Material Button 之类的东西效果很好。但是,侧边导航不适用于以下设置。

编辑:我做了更多测试,发现这与 Angular Material 特别相关,因为没有它就不会发生这些错误。我仍然不确定如何修复它。

我正在尝试为新组件设置一些基本测试,但我不断遇到错误。具体来说,在项目中添加@angular/material之后。目前的错误是:

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 配置区域中的声明与导入?

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

最佳答案

我添加了两个关键部分以避免这样的错误:

import { NO_ERRORS_SCHEMA } from '@angular/core';

被添加在页面的顶部并且:

schemas: [NO_ERRORS_SCHEMA],

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

这是做什么的?这告诉 Angular 不要在未知元素或属性上出错。现在这对 FOR THIS USE CASE 有效,因为我对集成测试不是很感兴趣。我相信在这种情况下这可能会导致问题。

我对单元测试很感兴趣,忽略模板属性对我来说没问题。添加这个可以让我达到那个水平。

这个答案是我目前所能得到的最完整的答案。

关于javascript - 用 jasmine 测试 Material Design Angular 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48913655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com