开玩笑:动作创作者问题

时间:2019-03-14 10:10:36

标签: reactjs jestjs

在测试动作创建者时,我想测试是否调用了正确的动作创建者,以及是否返回了正确的动作

action.js

export const AboutUs = {
    getAboutUsContentSuccess: 'getAboutUsContentSuccess/AboutUs',
    getBuildVersionSuccess: 'getBuildVersionSuccess/AboutUs'
};
export const getAboutUsContentSuccess = (data) => {
    return {
        type: AboutUs.getAboutUsContentSuccess,
        data
    }
} 

action.test.js

import * as actions from './actions'
describe('actions', () => {
   it('should create an action to getAboutUsContent', () => {
      const text = 'Finish docs'
      const expectedAction = {
        type: 'getAboutUsContentSuccess/AboutUs',
        text
      }
      console.log(expectedAction)
      console.log(actions.getAboutUsContentSuccess(text))
    expect(actions.getAboutUsContentSuccess(text)).toEqual(expectedAction)
  })
})

但是我遇到了以下错误

TypeError:无法读取未定义的属性'getAboutUsContentSuccess'

1 个答案:

答案 0 :(得分:1)

imports中似乎有一个错字,文件action.js的名称是单数。

只需将您的导入更改为:import * as actions from './action'