我对角和ngxs非常陌生,我正在编写一个小消息服务,提供了通过ngxs商店与firebase连接发送和接收消息的机会。
我试图为发送消息的方法编写一个测试。由于我与官方的ngxs测试文档不太合拍,所以我对此有一些问题。
因此,我目前(不起作用)对该测试的尝试是:
describe('SendMessage', () => {
let store: Store;
let testData: Message = {
author: 'testauthor',
text: 'testtext'
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgxsModule.forRoot([MessageState]),
NgxsModule.forRoot([AngularFirestore])],
}).compileComponents();
store = TestBed.get(Store);
store.reset(TEST_STATE);
}));
it('sends Messages', async(() => {
store.dispatch(new fromMessage.AddMessage(testData));
store.selectOnce(state => MessageState.getSentMessages).subscribe(message => {
expect(message).toEqual(testData);
})
}))
});与TEST_STATE在一起
export const TEST_STATE = {
messages: [{
author: 'testauthor',
text: 'testtext'
}]
}运行测试,我得到错误的Failed: States must be decorated with @State() decorator。
如何正确使用TEST_STATE作为测试AddMessage的状态?我的调度和选择应该是什么样的呢?
正如我说的,我是一个新手,对ngx和测试,如果我的代码不是那么好,非常抱歉。谢谢你的帮忙!
发布于 2020-06-03 07:42:33
测试床的imports语句中有两行可能产生错误Failed: States must be decorated with @State() decorator
请再次检查类MessageState和AngularFirestore是否用@State()装饰。
https://stackoverflow.com/questions/52224011
复制相似问题