【发布时间】:2018-12-19 15:00:56
【问题描述】:
我正在努力确定为什么我的玩笑测试永远找不到我的组件类/ 这是调试语句的组件输出
<FileLine file={{...}} readOnly={false} onSelectedRevisionChanged={[Function: mockConstructor]}>
<tr className="warning">
<td className="col-xs-2">
Data
</td>
<td className="col-xs-2">
<select className="revision-selection form-control" value="1" onChange={[Function: value]}>
<option value="1">
1
</option>
<option value="2">
2
</option>
</select>
</td>
<td className="col-xs-2">
Loading...
</td>
我开玩笑的测试是检查以下内容
it.only('sends selected revision when changed', () => {
const selectionCallBack = jest.fn();
const component = mount(<FileLine file={fileUnderTest} readOnly={false} onSelectedRevisionChanged={selectionCallBack} />);
//This will change the drop down to a different value
const revisionSelection = component.find('revision-selection');
console.log(component.debug());
expect(revisionSelection.length).to.equal(1);
revisionSelection.simulate('change', { target: { value: '2' } });
expect(selectionCallBack).toBeCalledWith('packageRoot/F5___/Apps/GM/GM.E86_r2');
});
expect 语句始终表明 revisionSelection 始终未定义。考虑到它在输出中显示了该类,这怎么可能是非常困惑的。
【问题讨论】:
-
您在选择器
component.find('revision-selection');中错过了.,应该是component.find('.revision-selection'); -
我已经厌倦了,仍然有完全相同的结果
-
如果您
console.log(component)会发生什么?你在输出中看到select标记了吗? -
@codenamev 返回 ReactWrapper {}
标签: javascript reactjs jestjs enzyme