【发布时间】:2018-02-15 12:19:44
【问题描述】:
我正在尝试编写一个测试,以确保我的方法根据组件的属性之一返回正确的值。 所以在我的单元测试中,我想设置组件属性的值,然后调用组件的方法,该方法应该基于该值返回一个布尔值,但是它没有按预期工作。
组件的方法很简单:
isLoading(): boolean {
return this.matches === [];
}
这是我当前的单元测试:
it('should have isLoading reflect whether there are matches', () => {
expect(component.matches).toBeDefined();
component.matches = [];
console.log(component.isLoading());
expect(component.isLoading()).toEqual(true);
component.matches = [{name: 'object'}];
console.log(component.isLoading());
expect(component.isLoading()).toEqual(false);
});
console.logs 都输出 false,我不知道为什么。
【问题讨论】:
-
Plunkr 总是有帮助 :)
-
请考虑为后代重新表述这个问题。这些不是属性,它们是属性。好吧,这听起来可能很迂腐,但在实践中,这种区别在 Angular 模板语言的上下文中非常重要。
标签: angular jasmine karma-runner karma-jasmine angular2-testing