gpt4 book ai didi

angular - 错误 : No test scheduler initialized when using jasmine-marbles with Spectator in Angular test

转载 作者:行者123 更新时间:2023-12-03 19:15:13 27 4
gpt4 key购买 nike

我的组件订阅了一个服务中的 Observable,它通过一个 Ngrx 选择器填充,为了简洁起见,这里概括为:

export class MyService {
signInFalied$: Observable<boolean>;

constructor(
private store: Store<MyAppState>,
) {
this.signInFailed$ = this.store.select(mySelectors.signInFailed);
}
}

我的组件具有基于此状态值的条件内容,我想测试是否显示了正确的内容。在我的测试中,我为该服务提供了一个模拟:
describe('My Test', () => {
let spectator: SpectatorHost<MyComponent>;

const createHost = createHostComponentFactory({
component: MyComponent,
declarations: [MyComponent],
providers: [
...,
mockProvider(MyService, {
signInFailed$: cold('x', { x: null }),
...
}),
],
imports: [...]
});
});

当我运行测试时,我得到:

Error: No test scheduler initialized



通过搜索我尝试过 setting my compile target to ES5

我此时也在使用最新版本的 jasmine-marbles:0.6.0

我究竟做错了什么?

最佳答案

cold需要在 async范围。所以你需要添加一个 beforeEach并在 async 中调用它范围:

import { async } from '@angular/core/testing';

describe('My Test', () => {
beforeEach(async(() => {

TestBed.configureTestingModule({
providers: [
...,
mockProvider(MyService, {
signInFailed$: cold('x', { x: null }),
...
}),
],
})
.compileComponents()
});


});

关于angular - 错误 : No test scheduler initialized when using jasmine-marbles with Spectator in Angular test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60980618/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com