My application has two Search Bars and displays content fetched from an external resource. When I type something in some of the bars it should filter the results and update an state which triggers re-rendering with new props. I'm trying to test that on a type event it updates accordingly but the test goes on forever.
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from './App';
const students = [/* ... */];
global.fetch = jest.fn();
describe('App', () => {
it('Displays correct results on search by name.', async () => {
global.fetch.mockImplementationOnce(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ students }) }));
render(<App />);
const searchByNameInput = await screen.findByPlaceholderText(/Search by name/);
userEvent.type(searchByNameInput(/Search by name/), 'Jo');
})
})
It is when I include userEvent that the test breaks. I've tried awaiting for it but doesn't help.
it goes on beyond a reasonable time
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment