mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 05:26:43 -06:00
update test
This commit is contained in:
parent
08f673802f
commit
e7eac5baa7
1 changed files with 36 additions and 3 deletions
39
test/api.ts
39
test/api.ts
|
@ -51,7 +51,7 @@ describe('API', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('error', async () => {
|
||||
test('api error', async () => {
|
||||
fetchMock.resetMocks();
|
||||
fetchMock.mockResponse(async (req) => {
|
||||
return {
|
||||
|
@ -80,7 +80,40 @@ describe('API', () => {
|
|||
}
|
||||
});
|
||||
|
||||
// TODO: ネットワークエラーのテスト
|
||||
test('network error', async () => {
|
||||
fetchMock.resetMocks();
|
||||
fetchMock.mockAbort();
|
||||
|
||||
// TODO: JSON以外が返ってきた場合のハンドリング
|
||||
try {
|
||||
const cli = new APIClient({
|
||||
origin: 'https://misskey.test',
|
||||
credential: 'TOKEN',
|
||||
});
|
||||
|
||||
await cli.request('i');
|
||||
} catch (e) {
|
||||
expect(isAPIError(e)).toEqual(false);
|
||||
}
|
||||
});
|
||||
|
||||
test('json parse error', async () => {
|
||||
fetchMock.resetMocks();
|
||||
fetchMock.mockResponse(async (req) => {
|
||||
return {
|
||||
status: 500,
|
||||
body: '<html>I AM NOT JSON</html>'
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
const cli = new APIClient({
|
||||
origin: 'https://misskey.test',
|
||||
credential: 'TOKEN',
|
||||
});
|
||||
|
||||
await cli.request('i');
|
||||
} catch (e) {
|
||||
expect(isAPIError(e)).toEqual(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue