Move testHelpers directory up one level

This commit is contained in:
2025-07-31 22:41:05 -04:00
parent b7299b8359
commit 14fbdc7408
28 changed files with 46 additions and 53 deletions

View File

@@ -0,0 +1,41 @@
import { jest } from "@jest/globals";
/**
* Function to update behavior of the global `fetch` function.
* Note that the Passio GO API returns status code 200 for failed responses.
* @param obj
* @param status
*/
export function updateGlobalFetchMockJson(
obj: any,
status: number = 200
) {
// @ts-ignore
global.fetch = jest.fn(() => {
return Promise.resolve({
json: () => Promise.resolve(obj),
status,
ok: status.toString().startsWith("2"), // 200-level codes are OK
})
});
}
/**
* Reset the global fetch function mock's JSON to return an empty object.
* @param obj
*/
export function resetGlobalFetchMockJson() {
updateGlobalFetchMockJson({});
}
export function updateGlobalFetchMockJsonToThrowSyntaxError() {
// @ts-ignore
global.fetch = jest.fn(() => {
return Promise.resolve({
json: () => Promise.reject(new SyntaxError("Unable to parse JSON")),
status: 200,
ok: true,
})
}) as jest.Mock;
}