【发布时间】:2019-08-18 03:50:51
【问题描述】:
我正在为我的组件编写单元测试。我想测试/覆盖我在订阅中调用函数 calculateJohnDoe 的部分。请参考以下内容:
ngOnInit(): void {
this.authStore$ = this.store.select('auth');
this.authStore$.subscribe(authData => {
if (authData && authData.myprop) {
this.calculateJohnDoe();
}
});
}
我在规范中尝试做的事情如下:
describe(..., () => {
let mockStore: MockStore<AuthState>;
// Testbed configuration
providers: [ Store ]
}).compileComponents();
mockStore = TestBed.get(Store);
...
it('should call the function', () => {
mockStore.setState({
myprop: true
});
const spy = jest.spyOn(LoginComponent.prototype, 'calculateJohnDoe');
expect(spy).toHaveBeenCalled();
});
...
});
但问题是我从未在调用的组件 ts 文件中获得 myprop 真正更新的存储事件/callack。
【问题讨论】:
标签: angular unit-testing jestjs ngrx