0

我使用createRoutingFactorywithSpectator但出现此错误:

this.router.url is undefined

我按照文档创建了我的测试文件:

    const createComponent = createRoutingFactory({
        mocks: [Router],
        component: MyComponent,
routes: [
      {
        path: '1',
        component: MyComponent,
      },
    ],
    url: [
      {
        path: '2',
        parameters: {},
        parameterMap: convertToParamMap({}),
      },
    ],
    ...

使用以下方法修复了子组件上的类似错误ng-mocks

declarations: [
      MockComponent(ChildComponent),
    ],

但这一次,this.router.url正在我正在测试的组件中使用,而不是在孩子中使用。

我尝试了这样的不同方法:

beforeEach(() => {
    spectator = createComponent();
    spectator.activatedRouteStub.setAllData([new Todo(133,'some 
   title','dsdsd','dsdsds','dsds','dsdss')]);
  });

(更多信息:https ://pretagteam.com/question/how-to-set-data-on-activatedroute-for-spectator-test )但没有运气。

我也没有得到与在 Spectator 中使用createRoutingFactorycreateServiceFactorywith的区别。mocks: [Router](更多信息https://netbasal.com/spectator-v4-a-powerful-tool-to-simplify-your-angular-tests-bd65a0bf317e

4

0 回答 0