与开玩笑的酶 - 期待的问题(收到).toBe(预期)

时间:2017-09-09 18:28:25

标签: javascript reactjs jestjs

我有一个问题是使用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;
&#13;
&#13;

&#13;
&#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;
&#13;
&#13;

来自.debug()

的日志

&#13;
&#13;
 console.log src\forecast\locationFinder\LocationFinderSearch.test.js:9
      <form>
        <input type="text" placeholder="Location" onChange={[Function]} />
        <input type="submit" value="Search" />
      </form>
&#13;
&#13;
&#13;

0 个答案:

没有答案