我有一个问题是使用jest和酶来验证这个测试用例。 基本上,事件处理程序会创建一个错误:
Issue with expect(received).toBe(expected)
如果我删除事件处理程序测试用例传递。
如果你查看函数.debug
的结果,我在eventhandler中看到一个函数。
知道如何解决这个问题吗?感谢任何解释!
import React from 'react'
// import { render, mount, shallow } from 'enzyme'
import { shallow } from 'enzyme'
import LocationFinderSearch from './LocationFinderSearch'
describe('<LocationFinderSearch />', () => {
it('should render', () => {
const wrapper = shallow(<LocationFinderSearch />)
console.log(wrapper.debug())
expect(shallow(
<LocationFinderSearch
onLocationChange='test'
onSearchClick='test'
/>
).contains(
<form>
<input type='text' placeholder='Location' onChange='test' />
<input type='submit' value='Search' />
</form>
)).toBe(true)
})
&#13;
import React from 'react'
const LocationFinderSearch = ({ onLocationChange, onSearchClick, inputValue }) => (
<form>
<input type='text' placeholder='Location' onChange={(e) => onLocationChange(e)} />
<input type='submit' value='Search' onClick={(e) => onSearchClick(e, inputValue)} />
</form>
)
export default LocationFinderSearch
&#13;
来自.debug()
console.log src\forecast\locationFinder\LocationFinderSearch.test.js:9
<form>
<input type="text" placeholder="Location" onChange={[Function]} />
<input type="submit" value="Search" />
</form>
&#13;