首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NGXS:测试动作

NGXS:测试动作
EN

Stack Overflow用户
提问于 2018-09-07 13:53:31
回答 1查看 3K关注 0票数 0

我对角和ngxs非常陌生,我正在编写一个小消息服务,提供了通过ngxs商店与firebase连接发送和接收消息的机会。

我试图为发送消息的方法编写一个测试。由于我与官方的ngxs测试文档不太合拍,所以我对此有一些问题。

因此,我目前(不起作用)对该测试的尝试是:

代码语言:javascript
复制
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在一起

代码语言:javascript
复制
export const TEST_STATE = {
    messages: [{
    author: 'testauthor',
    text: 'testtext'
    }]
}

运行测试,我得到错误的Failed: States must be decorated with @State() decorator

如何正确使用TEST_STATE作为测试AddMessage的状态?我的调度和选择应该是什么样的呢?

正如我说的,我是一个新手,对ngx和测试,如果我的代码不是那么好,非常抱歉。谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

发布于 2020-06-03 07:42:33

测试床的imports语句中有两行可能产生错误Failed: States must be decorated with @State() decorator

  1. NgxsModule.forRoot(MessageState)和
  2. NgxsModule.forRoot(AngularFirestore)

请再次检查类MessageStateAngularFirestore是否用@State()装饰。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52224011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档