首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角度2测试隔离(模板错误)

角度2测试隔离(模板错误)
EN

Stack Overflow用户
提问于 2017-02-04 02:24:19
回答 1查看 159关注 0票数 0

我有一个使用angular-cli (1.0.0-beta.26)创建的Angular (2.4.5)应用程序,并且我遇到了测试困难。我有一个简单的组件:

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

@Component({
  selector: 'app-empty',
  templateUrl: './empty.component.html',
  styleUrls: ['./empty.component.css']
})
export class EmptyComponent { }

( .html和.css都是空文件)和单元测试:

代码语言:javascript
复制
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { EmptyComponent } from './empty.component';

describe('EmptyComponent', () => {
  let component: EmptyComponent;
  let fixture: ComponentFixture<EmptyComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ EmptyComponent ]
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(EmptyComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

当启动npm run test时,测试失败,并显示错误:

代码语言:javascript
复制
Uncaught Error: Template parse errors: Can't bind to 'value' since it
isn't a known property of 'app-detail-section-item'.

这与一些其他组件有关,这些组件也在测试中。我不明白的是为什么这个组件会影响EmptyComponent的测试?是不是因为Webpack把考试捆绑在一起?我希望测试是隔离的。我可以使用schemas: [NO_ERRORS_SCHEMA]使测试通过,但这似乎不是正确的做法。

EN

回答 1

Stack Overflow用户

发布于 2017-02-07 15:27:40

最后,测试隔离的问题是由在某些测试中定义的超出describe()范围的beforeEach()函数造成的。这导致套件中的所有测试都运行了这些beforeEach(),并且我遇到了上面描述的副作用。

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

https://stackoverflow.com/questions/42030685

复制
相关文章

相似问题

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