Node.js 酶摩卡断言错误:预期0等于21

Node.js 酶摩卡断言错误:预期0等于21,node.js,reactjs,mocha.js,chai,enzyme,Node.js,Reactjs,Mocha.js,Chai,Enzyme,为一个应用程序编写一些单元测试,并在“描述”模块中碰壁 /* eslint-env mocha */ const React = require('react') const chai = require('chai') const { expect } = chai const Search = require('../js/Search') const ShowCard = require('../js/ShowCard') const enzyme = require('enzyme')

为一个应用程序编写一些单元测试,并在“描述”模块中碰壁

/* eslint-env mocha */
const React = require('react')
const chai = require('chai')
const { expect } = chai
const Search = require('../js/Search')
const ShowCard = require('../js/ShowCard')
const enzyme = require('enzyme')
const { shallow } = enzyme
const data = require('../public/data')

describe('<Search />', () => {
  it('should render as many shows as there are data for', () => {
    const wrapper = shallow(<Search />)
    expect(wrapper.find(ShowCard).length).to.equal(data.shows.length)
    console.log(wrapper.debug())
  })
})

根据上面的错误,问题从expection
equal(data.shows.length)
开始,但我看不出有什么错。谁能给我指出正确的方向吗?

哇,真尴尬。我将搜索构造函数的输入值的状态设置为“默认搜索项”-从而防止出现任何搜索结果,直到手动从输入中删除该字符串

替换为空字符串解决了问题。现在所有测试都通过了

<div className='shows'>
  {data.shows
    .filter((show) => `${show.title} ${show.description}`.toUpperCase().indexOf(this.state.searchTerm.toUpperCase()) >= 0)
    .map((show, index) => (
      <ShowCard {...show} key={index} id={index} />
  ))}
</div>
  <Search /> should render as many shows as there are data for:

  AssertionError: expected 0 to equal 21
  + expected - actual

  -0
  +21

  at Context.<anonymous> (App.spec.js:19:45)