diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-05-23 12:22:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-05-23 12:22:25 +0900 |
| commit | e7eac5baa70abeaca8489efff0499a4b6da1f8ff (patch) | |
| tree | fa4b40042bd7976e6f8c096062d596b20d621829 | |
| parent | fix test (diff) | |
| download | misskey-e7eac5baa70abeaca8489efff0499a4b6da1f8ff.tar.gz misskey-e7eac5baa70abeaca8489efff0499a4b6da1f8ff.tar.bz2 misskey-e7eac5baa70abeaca8489efff0499a4b6da1f8ff.zip | |
update test
| -rw-r--r-- | test/api.ts | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/test/api.ts b/test/api.ts index 6a1720a284..3380f3b630 100644 --- a/test/api.ts +++ b/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); + } + }); }); |