【发布时间】:2020-11-24 06:44:10
【问题描述】:
我检查控制台 .. shownCategories 不是空的,但在测试中是空的
it("in case edit should call filterCategories()", () => {
component.state == 'edit';
if (component.state == 'edit') {
const filterCategoriesSpy = spyOn(component, 'filterCategories').and.returnValue(
[{
hiddenVariants: 0,
id: 187910,
lang: "de",
name: "AMG/Exterieur",
plId: 5389,
refId: "1015001000",
type: "AMG",
visibleVariants: 5
}, {
hiddenVariants: 0,
id: 187911,
lang: "de",
name: "AMG/Interieur",
plId: 5389,
refId: "1015002000",
type: "AMG",
visibleVariants: 7,
}]);
expect(filterCategoriesSpy).toHaveBeenCalledTimes(1);
}
});
}}
这是函数:
public addFirstTable() {
console.log("addFirstTable");
//awel mara showncategories gaya fadya a lazm amlaha lw state msh edit
if (this.state != "compare") {
// this.shownCategories = this.allCategories.map(a => ({ ...a }));
this.shownCatgeories = this.FilterShownCategories();
console.log("shownCategories if state is not compare", this.shownCategories);
}
}
输出:
expected=1, received=0
【问题讨论】:
标签: angular unit-testing jasmine jestjs