Angular单元测试 - 出现错误:`Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?`

4

以下是我的单元测试基本设置:

  describe('ShellViewComponentAttributesComponent', () => {
  let fixture: ComponentFixture<ShellSelectLanguageForEEComponent>;
  let component: ShellSelectLanguageForEEComponent;
  let store: MockStore<any>;
  let location: Location;
  let router: Router;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ShellSelectLanguageForEEComponent],
      imports: [
        [
          RouterTestingModule.withRoutes([
            {
              path: 'SC/subject-curriculum',
              component: ShellSelectLanguageForEEComponent
            }
          ])
        ]
      ],
      providers: [
        provideMockStore({})
      ],

      schemas: [CUSTOM_ELEMENTS_SCHEMA]
    }).compileComponents();

    router = TestBed.get(Router);
    location = TestBed.get(Location);

    fixture = TestBed.createComponent(ShellSelectLanguageForEEComponent);
    router.initialNavigation();
    component = fixture.componentInstance;

    store = TestBed.get(Store);
    spyOn(store, 'dispatch');
  }));

当我运行代码时,出现了多个错误,例如:
console.warn node_modules/@angular/core/bundles/core.umd.js:25782
  Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?

我没有触发任何导航。这是必需的吗?因为我已经在模块中添加了它。如何处理这个问题?我查找了搜索结果,但没有解决方案适用于我。

1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接