react-testing-library – how to simulate file upload to a element?

I found a bit hacky solution and I’m not sure if it match the best practises in testing but I will share it with you it might help describe(“Upload files”, () => { let file; beforeEach(() => { file = new File([“(⌐□_□)”], “chucknorris.png”, { type: “image/png” }); }); test(“cover photo upload”, async () => { … Read more

How to select an option from a select list with React Testing Library

Add data-testid to the options <option data-testid=”select-option” key={item.key} value={item.key}> {item.label} </option> Then, in the test call fireEvent.change, get all the options by getAllByTestId and check the selected option: import React from ‘react’; import { render, fireEvent } from ‘@testing-library/react’; import App from ‘./App’; test(‘Simulates selection’, () => { const { getByTestId, getAllByTestId } = render(<App … Read more