React Testing Library: testing props sent to mocked child component

Viewed 9508

using jest and react testing library.

this seems so fundamental, yet i am missing it. how do you mock out a child component, but test that parent is calling it with the correct props? in this case i want to test parent.js and mock out the child component.

parent.js

import Child from './child'
const Parent = (props) => {
  const {firstname} = props;

  <Child name={firstname} />
}

test.js

import Parent from '../parent'
jest.mock('./child');

it('should render properly'), () => {
   render(<Parent firstname='bob'/>);
   expect('child').toBeCalledWith({ name: 'bob' });
}
1 Answers
Related