【发布时间】:2019-12-03 11:45:50
【问题描述】:
我正在使用 jest 测试我的反应功能。在我测试时,我收到错误 focus of null for document.getElementById 行。
我已经尝试过这个解决方案。 jest + enzyme, using mount(), document.getElementById() returns null on component which appear after _method call 但这对我不起作用。
这是我的 abc.js
clearSearch = () => {
const { typeSearchBox } = this.props;
this.setState({ searchPlaceholderValue: PROMPTRAISED });
this.setState({ searchValue: '' });
this.setState({ showClearIcon: false });
const searchBox = document.getElementById(`SearchBox_${typeSearchBox}`);
searchBox.focus();
};
这是我的 abc.test.js
it('+++ inputs valid filtered search text', () => {
categoryWrapper.find('ClearIcon').prop('onClick')();
});
点击 clearIcon clearseach 时触发。
【问题讨论】:
-
请添加测试文件中的代码。
标签: reactjs jestjs enzyme jsdom