Ожидается = 1, получено = 0 - почему моя функция не вызывается в тесте Angular? - PullRequest
0 голосов
/ 04 августа 2020

Я проверяю консоль .. shownCategories не пусто, но в тесте пусто. Я пытаюсь проверить, вызывается ли FilterShownCategories (), но получен ли он = 0, ожидается = 1

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);
         }
       });
     }}

Это веселье c:

  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

1 Ответ

0 голосов
/ 04 августа 2020

Я думаю, вы забыли выполнить функцию из теста.

Добавьте строку ниже

component.addFirstTable();

перед этим

expect(filterCategoriesSpy).toHaveBeenCalledTimes(1);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...