C
C
cester2018-07-05 10:11:25
JavaScript
cester, 2018-07-05 10:11:25

How to test render props, jest+enzyme?

Good afternoon! Please tell me how to test the render block if it comes with props?
The code

...
<div>
{drop && deleteBlock('Name')} // этот пропс выводит блок, который я хочу протестировать, что он вывелся
</div>
...

The test itself
it('should trigger archivedIcon prop when item is drop', () => {
    const props= {
      ...defaultProps,
      drop: true,
     deleteBlock: jest.fn(),
    };
    const enzymeWrapper = shallow(<DeleteItem{...props} />);

    expect(props.deleteBlock).toHaveBeenCalledTimes(1);
    expect(props.deleteBlock).toHaveBeenCalledWith('Name');
    expect(enzymeWrapper.find('[data-test="drop"]')).toHaveLength(1); // вот здесь проблема 
  });

gives an error message
Expected value to have length:
      1
    Received:
      {"length": 0, Symbol(enzyme.__root__): {"length": 1,
....

For tests, jest + enzyme is used.
I will be grateful for your help)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question