所以我有一个特殊的问题,在我的 react 组件中,我使用了如下命令:
document.getElementById('modalsContainer').appendChild(recognitionProfileZoom);
document.getElementById('modalsContainer').appendChild(categoryZoom);
和:
document.getElementById('cddoccategoryzoom').value;
但是这些由 ID 指定的元素在我的组件中不存在。
如何在测试中创建这些对象?
下面的代码将使用这些元素,但由于它们不存在而失败(hideModal 函数利用了之前的 document.append)
describe("CaptureProfileModal functions tests", function() {
it('Should hide the modal', function() {
var wrapper, instance;
wrapper = mount(
<CaptureProfileModal
gridAction={1}
captureSettingCode={15}
fields={mockedFields}/>
);
wrapper.setState({
showModal: true
});
instance = wrapper.component.getInstance();
instance.hideModal();
});