How to use the @testing-library/react.fireEvent.click function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atlassian / react-beautiful-dnd / test / test-setup.js View on Github external
afterEach(() => {
    cleanup();
    // lots of tests can leave a post-drop click blocker
    // this cleans it up before every test
    fireEvent.click(window);

    if (window.getComputedStyle.mockRestore) {
      window.getComputedStyle.mockRestore();
    }

    if (Element.prototype.getBoundingClientRect.mockRestore) {
      Element.prototype.getBoundingClientRect.mockRestore();
    }
  });
}
github syndesisio / syndesis / app / ui-react / packages / ui / __tests__ / Customization / ExtensionListItem.spec.tsx View on Github external
// description
    expect(queryAllByText(extensionDescription)).toHaveLength(1);

    // name
    expect(queryAllByText(extensionName)).toHaveLength(1);

    // update button
    expect(queryAllByText(updateText)).toHaveLength(1);

    // delete button
    const deleteButton = getByText(deleteText);
    expect(deleteButton).not.toHaveAttribute('disabled'); // delete should be enabled

    // click the delete button so that the delete confirmation dialog opens
    fireEvent.click(deleteButton);

    // click the confirmation dialog delete button and make sure callback is called
    const dialog = getAllByRole('dialog')[0];
    fireEvent.click(getDialogButton(dialog, deleteText));
    expect(mockOnDelete).toHaveBeenCalledTimes(1);
  });
github alibaba / uform / packages / react-schema-renderer / src / __old_tests__ / dynamic.spec.js View on Github external
const { queryAllByTestId, queryByText, queryAllByText } = render(
    
  )
  expect(queryAllByTestId('input').length).toBe(2)
  let removes
  await sleep(33)
  removes = queryAllByText('Remove Field')
  fireEvent.click(removes[removes.length - 1])
  await sleep(33)
  removes = queryAllByText('Remove Field')
  fireEvent.click(removes[removes.length - 1])
  await sleep(33)
  expect(queryAllByTestId('input').length).toBe(0)
  await sleep(33)
  fireEvent.click(queryByText('Add Field'))
  await sleep(33)
  fireEvent.click(queryByText('Add Field'))
  await sleep(33)
  expect(queryAllByTestId('input').length).toBe(2)
  expect(queryAllByTestId('input')[0].value).toBe('123')
  expect(queryAllByTestId('input')[1].value).toBe('123')
})
github VNG-Realisatie / nlx / management-ui / src / components / ConfirmationModal / testUtils.js View on Github external
export function clickConfirmButton(button) {
  jest.useFakeTimers()
  fireEvent.click(button)
  jest.runAllTimers()
  jest.useRealTimers()
}
github zendeskgarden / react-containers / packages / modal / src / ModalContainer.spec.tsx View on Github external
it('closes modal onClick', () => {
      const { getByTestId } = render();

      fireEvent.click(getByTestId('close'));
      expect(onCloseSpy).toHaveBeenCalled();
    });
  });
github async-library / react-async / packages / react-async-devtools / src / index.spec.js View on Github external
test("allows toggling interception of requests", async () => {
    const promiseFn = () => Promise.resolve("done")
    const { getByText, getByLabelText, queryByText, rerender } = render()
    fireEvent.click(getByLabelText("Pause new requests"))
    rerender(
      <>
        
        
      
    )
    await waitForElement(() => getByText("Pending"))
    expect(queryByText("Fulfilled")).not.toBeInTheDocument()
    fireEvent.click(getByText("run"))
    await waitForElement(() => getByText("Fulfilled"))
  })
github mongodb / leafygreen-ui / packages / tabs / src / Tabs.spec.tsx View on Github external
test('clicking a tab does not change the active tab', () => {
      const tab = getByText('Name A');
      fireEvent.click(tab);

      const secondContent = getByText('Second Content');
      expect(secondContent).toBeInTheDocument();
    });
github mongodb / leafygreen-ui / packages / radio-group / src / RadioGroup.spec.tsx View on Github external
throw new Error('Could not find uncontrolled container component');
  }

  const radioLabel = uncontrolledContainer.firstChild;

  if (!typeIs.element(radioLabel)) {
    throw new Error('Could not find the label element');
  }

  const radio = radioLabel.firstChild;

  if (!typeIs.input(radio)) {
    throw new Error('Could not find the radio input element');
  }

  fireEvent.click(radioLabel);

  test('onChange fires once when the label is clicked', () => {
    expect(uncontrolledOnChange.mock.calls.length).toBe(1);
  });

  test('radio button becomes checked when clicked', () => {
    expect(radio.checked).toBe(true);
  });

  describe('and the default prop is set', () => {
    const uncontrolledContainer = render(
      
        Radio Button 1
        
          Radio Button 1
github marmelab / react-admin / packages / ra-ui-materialui / src / input / RadioButtonGroupInput.spec.tsx View on Github external
{ id: 2, name: 'Mastercard' },
        ];
        const { getByLabelText } = render(
            <form> (
                    
                )}
            /&gt;
        );
        const input = getByLabelText('Mastercard') as HTMLInputElement;
        expect(input.checked).toBe(false);
        fireEvent.click(input);
        expect(input.checked).toBe(true);
    });
</form>
github openfun / marsha / src / frontend / components / DashboardVideoPaneDownloadOption / index.spec.tsx View on Github external
await act(async () => {
      fireEvent.click(getByLabelText('Allow video download'));
      return deferred.resolve({ ...video, show_download: true });
    });