DEV Community

Discussion on: Enzyme or react-testing-library and why?

 
lacasa profile image
𝙻𝚊𝚌𝚊𝚜𝚊 • Edited

You can create your custom selectors like this:

import { queryByAttribute, render } from '@testing-library/react';

const getByName = queryByAttribute.bind(null, 'name');

it('should...', () => {
  const { container } = render(<Component />);
  expect(getByName(container, 'the-name').toEqual(...)
})

I have some custom selectors created in a utils file (name, type, id...).