![](/img/trans.png)
[英]How to use router.navigateByUrl and router.navigate in Angular
[英]How to mock router.navigateByUrl(…).then in Angular with Karma and Jasmine
我的問題很簡單,我以這種方式使用 navigateByUrl() 然后 then() :
this.router
.navigateByUrl(PAGE1, {
skipLocationChange: true
})
.then(() => {
this.router.navigate([PAGE2]);
});
我模擬了導航,navigateByUrl 然后這樣:
const mockRouter = {
navigate: () => {},
navigateByUrl(url: string) { return url; },
then: () => {}
};
它適用於導航和導航ByUrl,但不適用於那時,我不知道如何模擬這個 function。 我該如何進行?
感謝 jonrsharpe 的建議,我找到了解決方案。 解決方案是以這種方式模擬 navigateByUrl:
navigateByUrl: () => {
return {
then: () => {}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.