angular - Angualr 单元测试 - 在 Angular 区域外触发导航时出现错误,您是否忘记调用 'ngZone.run()'?
问题描述
这是我对单元测试的基本设置:
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()'?
我没有触发任何导航。是必需的吗?因为我已经在模块中添加了。如何处理这个问题。我遇到了搜索,但没有解决方案适合我。
解决方案
推荐阅读
- chromecast - 如何将我的自定义接收器 chromecast(CAF)的媒体播放器更改为另一个播放器
- python - 计算克隆张量 Pytorch 的 grads
- gradle - IntelliJ Idea 中的 Kotlin 包结构
- spring - Spring docs - Open API 3 - 如何将默认值设置为正文?
- dictionary - 如何将 TCL 字典形成为字符串以将其作为字符串变量传递?
- javascript - 从 div 悬停到 div 时,jQuery Dropdown 不断关闭
- python - 如何更改熊猫日期框列
- javascript - How to close CSS menu when clicking on links with JS?
- c++ - Qt 语言学家、宏和预处理器
- python - 如何创建一个从 1 开始的 ID,在排序后每次开始另一个(字符串,时间)变量增加 1(分钟)?