UI Testing with Enzyme

  Pros:

  • Very easy to set up for unit testing regardless of what other testing tools are used
  • Does not require a special environment and configuration
  • Good documentation and simple API
  • Very fast
  • Huge community
  • Provides facilities for testing the instance of the component directly:

describe('Tags multiselect', () => {
  it('should pass correct data options to the Multiselect component', () => {
    const tags = [
      { id: '1'label: 'B' },
      { id: '2'label: 'A' },
    ];

    const wrapper = mount(
      <Tags
        {...baseProps}
        tags={tags}
      />
    );

    const propsPassedToMultselection = wrapper.find(MultiSelection).props();

    expect(propsPassedToMultselection.dataOptions).to.deep.equal([
      { value: 'a'label: 'a' },
      { value: 'b'label: 'b' },
    ]);
  });
});


Cons:

  • Issues with testing components using react hooks
  • Provides facilities for testing the instance of the component directly. This can encourage harmful testing approaches.