简体   繁体   English

嘲笑 Angular navigateByUrl 仍在运行页面重新加载

[英]Mocked Angular navigateByUrl still running page reload

I am trying to write a test for a button click which triggers a navigateByUrl function call with some params.我正在尝试为按钮单击编写一个测试,该测试会触发带有一些参数的 navigateByUrl function 调用。

I have mocked Router and provided to the testing module as such我已经模拟了路由器并提供给测试模块

let mockRouter = {
navigateByUrl: jasmine.createSpy("navigateByUrl").and.callFake(() => {
  console.log("fake is called");
}),
};

beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientModule],
      declarations: [RecoverPasswordComponent],
      providers: [{ provide: Router, useValue: mockRouter }],
    }).compileComponents();
  }));

when i click the button and navigateByUrl is triggered, i am getting the console as written but i am also getting a error as Some of your tests did a full page reload!当我单击按钮并触发 navigateByUrl 时,我得到了控制台,但我也收到了错误,因为Some of your tests did a full page reload! which means that actual navigateByUrl is triggered.这意味着触发了实际的 navigateByUrl。

I am not able to get an idea of, if the function is spied than why the actual function call is triggered?我不知道,如果 function 被监视而不是为什么实际的 function 调用被触发?

I Finally figured out what was causing this, So basically i had a form in which my button was stated.我终于弄清楚了是什么原因造成的,所以基本上我有一个表格,其中说明了我的按钮。 as the form was not binded with ng-submit callback so on clicking the button the default event for a form button was triggered which reloaded the test suite.由于表单未与 ng-submit 回调绑定,因此单击按钮时会触发表单按钮的默认事件,从而重新加载测试套件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果页面仍在加载,Angular router.navigateByUrl()无法正常工作 - Angular router.navigateByUrl() not working if page is still loading Angular 的 .navigateByUrl() 导航到页面,但没有呈现 html - Angular's .navigateByUrl() navigates to the page but html is not rendered 页面闲置后,Angular navigationByUrl具有巨大延迟 - Angular navigateByUrl with huge delay after page is idle router.navigateByUrl()导致导航到根并重新加载,角度为2.4.7 - router.navigateByUrl() causes navigation to root and reload, angular 2.4.7 使用Angular 7的NavigateByUrl发送数据 - to send data with NavigateByUrl of Angular 7 Angular 中带有 navigateByUrl 的转发状态 - Forward state with navigateByUrl in Angular navigate 和 navigateByUrl 不导航到页面 - navigate and navigateByUrl not navigating to the page Angular Router:用false解析的navigationByUrl() - Angular Router: navigateByUrl() resolving with false 在navigateByUrl()时Angular动态路由名称不起作用,需要刷新页面 - In Angular dynamic route name not working when navigateByUrl(), its need to refresh the page 首次渲染页面时,如何调试 Ionic Angular navigateByUrl() - How to debug Ionic Angular navigateByUrl() when not working on first time rendering of page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM