Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: aborted requests should not trigger error state #209

Merged
merged 2 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading