tengo este codigo:
wrapper.find('.table-year-head button').at(1).simulate('click'); wrapper .find('.table-months') .at(1) .find('input[type="checkbox"]') .forEach(node => { expect(node.props().checked).toEqual(true); }); Sé que puedo usar data-testid para los selectores, pero ¿cómo puedo seleccionar el enésimo?
Puede utilizar una consulta getAllBy :
const table = wrapper.getAllByRole('table')[1] fireEvent.click(within(table).getByRole('button'));El problema es que no podría usar los selectores de CSS de la forma en que lo hace con Enzyme. La biblioteca de prueba de React tiene que ver con la semántica. Le recomendaría agregar etiquetas a sus tablas usando el atributo aria-label :
<table className="years" aria-label="Year table"> ...De esta manera, serías capaz de hacer:
const yearTable = wrapper.getByRole('table', {name: 'Year table'}); fireEvent.click(within(yearTable).getByRole('button')); const monthTable = screen.getByRole('table', {name: 'February table'}); const checkbox = within(monthTable).getByRole('checkbox') fireEvent.click(checkbox); expect(checkbox).toBeChecked();