Open HenrikHartiala opened 11 months ago
Here are the two functions:
export const expectErrorResponse =
(expectedErrorMsg?: string) => (response: Response) => {
if (response.statusCode >= 200 && response.statusCode < 300)
throw new Error('Request succeeded even though it was expected to fail');
expect(response).toEqual(
expect.objectContaining({
errors: expect.any(Array),
}),
);
if (expectedErrorMsg) {
expect(JSON.stringify(response)).toContain(expectedErrorMsg);
}
};
export const expectNoErrorResponse = (response?: unknown) => {
expect(response).toEqual(
expect.not.objectContaining({
errors: expect.any(Array),
}),
);
};
Refactor or at least rename this function to be more clear. Currently there are two functions: expectErrorResponse and expectNoErrorResponse, and the first one is a higher order function and the latter is not. So the naming is not consistent.
Renaming is one option, but I do not see any value for the first function to be a higher order function, so I would rather just refactor it to a normal function.