I am using React-testing-library and getting an error on the last line which is: expect (title.value).toBe("testtitle");})}) . The error message is Property 'value' does not exist on type 'HTMLElement'. How can I rectify this error message in order to write this code efficiently?
测试文件
<Router history={history}>
<Route render={(props) =>
<NewQuestion {...props} onSave={jest.fn()}/>}/>
</Router>)
const title= getByPlaceholderText("What's your question? Be specific");
fireEvent.change(title, {target: {value: "testtitle"}})
expect (title.value).toBe("testtitle");})})
最佳答案
您应该将 title
变量转换为 HTMLInputElement
才能真正拥有 value
属性。尝试以下代码:
const title = getByPlaceholderText("test") as HTMLInputElement;
关于reactjs - React 测试库中的类型 'value' 不存在属性 'HTMLElement',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59986806/