How to test Angular2's router.navigate?

前端 未结 4 1043
囚心锁ツ
囚心锁ツ 2021-01-31 07:58

I\'ve run into missing messages in other unit tests, but just to have a nice isolated example, I created an AuthGuard that checks if a user is

4条回答
  •  自闭症患者
    2021-01-31 08:59

         it(`editTemplate() should navigate to template build module with query params`, inject(
            [Router],
            (router: Router) => {
              let id = 25;
              spyOn(router, "navigate").and.stub();
              router.navigate(["/template-builder"], {
                queryParams: { templateId: id }
              });
              expect(router.navigate).toHaveBeenCalledWith(["/template-builder"], {
                queryParams: { templateId: id }
              });
            }
          ));
    

提交回复
热议问题