单元测试错误:无法读取未定义的属性“ map”

时间:2019-01-17 14:56:27

标签: javascript reactjs unit-testing

我正在尝试对以下代码进行单元测试,但不确定如何模拟其中包含地图的this.props

错误:无法读取未定义的属性“地图”

这个道具正确吗? this.props.fromStatusList。我有其他道具了

这是BatchAccount.js代码的一部分:

 renderFromDropdown = () => {
let fromList = this.props.fromStatusList;
let result = fromList.map((item) => {

这是我在BatchAccount.test.js中嘲弄道具的方式

describe( 'BatchUpdateAccountModal test: ', () => {

let tree;
let baseProps;
let mockfromStatusList;

然后我将它们列在beforeEach(()=>

 beforeEach(() => {

    baseProps = {
fromStatusList : mockfromStatusList,

并运行测试以检查其是否与所有道具一起渲染,例如:

  it(' Should render with all of the props ', () => {  
tree = renderer.create(<BatchUpdateAccountModal {...baseProps} />)
let treeJson = tree.toJSON()
expect(treeJson).toMatchSnapshot();
tree.unmount()

});

0 个答案:

没有答案