dceddia / getting-started-with-tdd-in-react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

containsAllMatchingElements failed with propTypes

zhaolc90 opened this issue · comments

When adding Test 4: Passing Down the Function

after add

InputArea.propTypes = {
  onSubmit: PropTypes.func.isRequired
};

Test 1 will show me a Warning

√ should render InputArea and BeerList
  BeerListContainer
<div>
  <InputArea onSubmit={[Function: bound addItem]} />
  <BeerList />
</div>
Warning: Failed prop type: The prop `onSubmit` is marked as required
 in `InputArea`, but its value is `undefined`.
    in InputArea
  it('should render InputArea and BeerList', () => {
    const wrapper = shallow(<BeerListContainer/>);
    console.log(wrapper.debug())
    expect(wrapper.containsAllMatchingElements([
       <InputArea/>,                            // this line cause propTypes validation
      <BeerList/>
    ])).to.equal(true);
  });

It looks like the warning is because there's no onSubmit being passed to InputArea. If you replace that line with:

<InputArea onSubmit={jest.fn()}/>

That should get rid of the warning, and hopefully not break the assertion...