2016-12-05 3 views
0

앱에 대한 단위 테스트를 작성하고 설명 블록에서 벽을 치는 것. 위의 오류에 따르면효소 모카 AssertionError : 0 ~ 21로 예상 됨

<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) 

:

<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> 

(wrapper.find(ShowCard).length)(data.shows.length) 동일해야하지만,이 오류를주고 :

/* 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()) 
    }) 
}) 

검색 구성 요소의 코드는 다음과 ShowCard 렌더링됩니다 문제는 기대치 인 equal(data.shows.length)에서 시작됩니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니까?

답변

0

와우, 얼마나 당황 스럽습니까. 검색 생성자의 입력 값을 "기본 검색 용어"로 설정 했으므로 문자열이 입력에서 수동으로 제거 될 때까지 검색 결과가 나타나지 않습니다.

빈 문자열로 바꾸면 문제가 해결됩니다. 모든 테스트가 끝납니다.