Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法读取属性';增补列表器';在带有Ref的测试中为null_Reactjs_Jestjs_Enzyme - Fatal编程技术网

Reactjs 无法读取属性';增补列表器';在带有Ref的测试中为null

Reactjs 无法读取属性';增补列表器';在带有Ref的测试中为null,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我向div添加了一个ref,并在componentDidMount()中向ref添加了一个事件侦听器。我发现了错误 无法在我的酶测试中读取null的属性'addEventListener' 我知道,如果在添加事件侦听器之前检查元素,这可能会起作用,但我想知道是否可以向测试中添加更“正确”的内容 类MyComponent扩展了React.Component{ 建造师(道具){ 超级(道具); this.element=React.createRef(); } componentDidMount()

我向div添加了一个ref,并在
componentDidMount()
中向ref添加了一个事件侦听器。我发现了错误

无法在我的酶测试中读取null的属性'addEventListener'

我知道,如果在添加事件侦听器之前检查元素,这可能会起作用,但我想知道是否可以向测试中添加更“正确”的内容

类MyComponent扩展了React.Component{ 建造师(道具){ 超级(道具); this.element=React.createRef(); } componentDidMount(){ this.element.current.addEventListener('rowClicked',this.onRowClicked); } render(){ 返回( {this.element=element}> 试验室 ) } } 这是我的测试:

test(“应该呈现”,()=>{
const wrapper=shallow().dive();
const content=wrapper.find(“.content”);
expect(content.toMatchSnapshot();
});