Skip to content

Commit

Permalink
test: refactor test to pass linter
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahdayan committed Apr 7, 2023
1 parent 148ddda commit f2529c0
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions packages/autocomplete-core/src/__tests__/getInputProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,29 +565,33 @@ describe('getInputProps', () => {
});
});

/* eslint-disable-next-line jest/no-done-callback */
test('lets user handle the errors', (done) => {
const getSources = jest.fn((..._args: any[]) => {
return [
createSource({
getItems() {
return new Promise<any>((resolve, reject) => {
reject(new Error('Fetch error'));
}).catch((err) => {
expect(err).toEqual(expect.any(Error));
done();
return [];
});
},
}),
];
});
test('lets user handle the errors', async () => {
const onError = jest.fn();

const { inputElement } = createPlayground(createAutocomplete, {
getSources,
getSources: jest.fn(() => {
return [
createSource({
getItems() {
return new Promise<any>((_, reject) => {
reject(new Error('Fetch error'));
}).catch((err) => {
onError(err);

return [];
});
},
}),
];
}),
});

userEvent.type(inputElement, 'a');

await runAllMicroTasks();

expect(onError).toHaveBeenCalledTimes(1);
expect(onError).toHaveBeenCalledWith(new Error('Fetch error'));
});

test('clears stalled timeout', async () => {
Expand Down

0 comments on commit f2529c0

Please sign in to comment.