mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
refactor ApiResponseError check into a function
This commit is contained in:
@@ -29,7 +29,11 @@ function updateGlobalFetchMockJson(
|
||||
* @param obj
|
||||
*/
|
||||
function resetGlobalFetchMockJson() {
|
||||
updateGlobalFetchMockJson({})
|
||||
updateGlobalFetchMockJson({});
|
||||
}
|
||||
|
||||
async function assertAsyncCallbackThrowsApiResponseError(callback: () => Promise<any>) {
|
||||
await expect(callback).rejects.toThrow(ApiResponseError);
|
||||
}
|
||||
|
||||
describe("ApiBasedRepositoryLoader", () => {
|
||||
@@ -58,18 +62,17 @@ describe("ApiBasedRepositoryLoader", () => {
|
||||
it("throws the correct error if the API response contains no data", async () => {
|
||||
updateGlobalFetchMockJson(fetchSystemDataFailedResponse);
|
||||
|
||||
// Jest is so confusing
|
||||
await expect(async () => {
|
||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||
await loader.fetchAndUpdateSystemData();
|
||||
}).rejects.toThrow(ApiResponseError);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws the correct error if HTTP status code is not 200", async () => {
|
||||
updateGlobalFetchMockJson(fetchSystemDataFailedResponse, 400);
|
||||
|
||||
await expect(async () => {
|
||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||
await loader.fetchAndUpdateSystemData();
|
||||
}).rejects.toThrow(ApiResponseError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user