React Testing Library internal elements

Sun Jul 28 2019
import { render } from '@testing-library/react';

  it.only('call filtered items after invoice deletion', async () => {
    const props = {
      deleteInvoiceApiActionCreator: jest.fn(),
      getAllInvoicesWithFilters: jest.fn(),
    }
    const { container } = render(<TestedComponent {...props} />)

    const td = container.querySelector('table tbody tr td:last-child');
    const deleteIcon = td.querySelector('button');

    fireEvent.click(deleteIcon);

    const actionButtons = td.querySelectorAll('button');
    const deleteButton = actionButtons[0];
    
    await fireEvent.click(deleteButton);

    expect(props.deleteInvoiceApiActionCreator).toHaveBeenCalled();
    expect(props.getAllInvoicesWithFilters).toHaveBeenCalled();
  });