1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-24 11:38:34 +09:00

update test

This commit is contained in:
syuilo 2021-05-23 12:22:25 +09:00
parent 08f673802f
commit e7eac5baa7

View File

@ -51,7 +51,7 @@ describe('API', () => {
}); });
}); });
test('error', async () => { test('api error', async () => {
fetchMock.resetMocks(); fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => { fetchMock.mockResponse(async (req) => {
return { 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);
}
});
}); });