Skip to content

Commit

Permalink
test(api-calls): update test for new node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nandi95 committed Apr 11, 2024
1 parent f26f6f8 commit 117d23c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions tests/Services/ApiResponseHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,12 @@ describe('ApiResponseHandler', () => {

it('should throw JSON error if returned data cannot be parsed', async () => {
fetchMock.mockResponseOnce('{"key":"value"');
let expectedError = '"invalid json response body at reason: Unexpected end of JSON input"';
let expectedError = '"Expected \',\' or \'}\' after property value in JSON at position 14"';
const nodeVersion = parseInt(process.versions.node);

// eslint-disable-next-line jest/no-conditional-in-test
if (nodeVersion >= 19) {
expectedError = '"invalid json response body at reason: ' +
'Expected \',\' or \'}\' after property value in JSON at position 14"';

// eslint-disable-next-line jest/no-conditional-in-test
if (nodeVersion >= 21) {
expectedError = expectedError.slice(0, -1) + ' (line 1 column 15)"';
}
if (nodeVersion >= 21) {
expectedError = expectedError.slice(0, -1) + ' (line 1 column 15)"';
}

await expect(handler.handle(fetch('url'))).rejects.toThrowErrorMatchingInlineSnapshot(expectedError);
Expand Down Expand Up @@ -121,3 +115,4 @@ describe('ApiResponseHandler', () => {
expect(apiResponse.headers.get('Content-Length')).toBe('12345');
});
});

0 comments on commit 117d23c

Please sign in to comment.