Angular单元测试:未捕获错误:未捕获(在Promise中):错误:无法匹配任何路由
创始人
2024-10-23 23:01:16
0

这个问题通常是在单元测试中发生的,因为在单元测试中使用的路由器是特定的路由器,而不是应用程序中的路由器。因此,需要在测试环境中提供一个路由器配置。

以下是示例代码:

在你的测试文件中,使用TestBed来配置路由器并使用TestingModule来导入所需的模块和组件:

import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [
        RouterTestingModule // import the RouterTestingModule here
      ],
      declarations: [
        AppComponent
      ],
    }).compileComponents();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });
});

这个示例中,RouterTestingModule被导入以供使用。这允许在测试环境中使用路由器。 它应该被导入到任何需要在单元测试中使用路由器的测试文件中。

相关内容

热门资讯

透视真的!德州来玩辅助器,起点... 透视真的!德州来玩辅助器,起点休闲辅助,确实真的是有挂(总结详细教程)-哔哩哔哩1、玩家可以在起点休...
透视必胜!hhpoker透视脚... 透视必胜!hhpoker透视脚本(透视)开挂辅助攻略(真是存在有挂)-哔哩哔哩一、hhpoker透视...
透视有挂!wepoker有辅助... 透视有挂!wepoker有辅助工具吗,哈糖大菠萝免费辅助器,总结教程(好像存在有挂)-哔哩哔哩该软件...
最新消息!拱趴大菠萝十三水辅助... 最新消息!拱趴大菠萝十三水辅助,永久免费脚本透视工具,好像真的有挂(解密分享教程)-哔哩哔哩1、完成...
透视有挂!hhpoker可以控... 透视有挂!hhpoker可以控制牌吗,德普之星app安卓版破解版,手筋教程(真是是有挂)-哔哩哔哩1...
透视最新版!约局吧德州有挂吗(... 透视最新版!约局吧德州有挂吗(透视)开挂辅助app(一贯有挂)-哔哩哔哩1、下载好约局吧德州有挂吗辅...
透视数据!pokerrrr2辅... 透视数据!pokerrrr2辅助,wepoker私人局怎么玩,学习教程(一贯是真的挂)-哔哩哔哩1、...
透视透视挂!wepoker怎么... 透视透视挂!wepoker怎么提高运气,欢乐达人暗堡链接辅助,一直真的有挂(专业力荐教程)-哔哩哔哩...
透视检测!aa poker辅助... 透视检测!aa poker辅助包(透视)开挂辅助技巧(原来真的是有挂)-哔哩哔哩1、aa poker...
透视工具!pokemmo脚本辅... 透视工具!pokemmo脚本辅助下载,德扑之心免费透视,学习教程(一直存在有挂)-哔哩哔哩1)pok...