Skip to content

Commit

Permalink
test: aborted requests should not trigger error state (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored May 21, 2024
1 parent 1fbfdc5 commit df3a5dd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ test('Should abort previous request', async () => {
appName: 'web',
};
const client = new UnleashClient(config);

await client.start();
client.updateContext({ userId: '123' }); // abort 1
client.updateContext({ userId: '456' }); // abort 2
Expand All @@ -622,6 +623,25 @@ test('Should abort previous request', async () => {
abortSpy.mockRestore();
});

test('Should not trigger error on abort', async () => {
fetchMock.mockResponse(JSON.stringify(data));

const config: IConfig = {
url: 'http://localhost/test',
clientKey: '12',
appName: 'web',
};
const client = new UnleashClient(config);
client.on(EVENTS.ERROR, () => {
throw new Error('abort should not trigger error');
});

await client.start();

fetchMock.mockAbort();
await client.updateContext({ userId: '789' });
});

test.each([400, 401, 403, 404, 429, 500, 502, 503])(
'Should publish error when fetch receives a %d error',
async (errorCode) => {
Expand Down

0 comments on commit df3a5dd

Please sign in to comment.