Skip to content

Commit

Permalink
#38
Browse files Browse the repository at this point in the history
- тесты
  • Loading branch information
krutoo committed Jun 14, 2024
1 parent 005784c commit c243d34
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/http/__test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ describe('FetchUtil', () => {

const responseDone = new Response('{ "data": "foo" }', { status: 200, statusText: 'GOOD' });
const responseFail = new Response('{ "data": "bar" }', { status: 400, statusText: 'BAD' });
const responseInvalidJson = new Response('{ aaAA }', { status: 200, statusText: 'INVALID' });
const responseFailInvalidJson = new Response('{ aaAA }', {
status: 400,
statusText: 'INVALID',
});

expect(await handleDone(responseDone)).toEqual({
ok: true,
Expand All @@ -103,6 +108,24 @@ describe('FetchUtil', () => {
headers: new Headers({ 'content-type': 'text/plain;charset=UTF-8' }),
});

expect(await handleDone(responseInvalidJson)).toEqual({
ok: true,
data: null,
error: null,
status: 200,
statusText: 'INVALID',
headers: new Headers({ 'content-type': 'text/plain;charset=UTF-8' }),
});

expect(await handleDone(responseFailInvalidJson)).toEqual({
ok: false,
data: null,
error: new Error(`Request failed with status code ${400}`),
status: 400,
statusText: 'INVALID',
headers: new Headers({ 'content-type': 'text/plain;charset=UTF-8' }),
});

const error = new Error('Fetch failed');

expect(await handleFail(error)).toEqual({
Expand Down

0 comments on commit c243d34

Please sign in to comment.