Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Failure: Mismatch in Error Message Formatting for Non-JSON Response in fetchBaseQuery #4631

Open
Adagedo opened this issue Sep 19, 2024 · 2 comments

Comments

@Adagedo
Copy link

Adagedo commented Sep 19, 2024

When running tests for the FetchBaseQuery with a non-JSON body, there is a mismatch in the expected and received error messages. Specifically, the error formatting differs in how it handles unexpected tokens in the response.

Expected Error

"error": "SyntaxError: Unexpected token h in JSON at position 1"

Recieved Error

"error": "SyntaxError: Unexpected token 'h', \"this is not json!\" is not valid JSON"

Test Case:
This occurs in the test fetchBaseQuery › non-JSON-body › success: should fail gracefully (default="json" responseHandler) at line 176 in src/query/tests/fetchBaseQuery.test.tsx.

       174 |       expect(res.meta?.request).toBeInstanceOf(Request)YN0000:       175 |       expect(res.meta?.response).toBeInstanceOf(Object)
 YN0000:     > 176 |       expect(res.error).toEqual({
 YN0000:           |                         ^
 YN0000:       177 |         status: 'PARSING_ERROR',
 YN0000:       178 |         error: 'SyntaxError: Unexpected token h in JSON at position 1',
 YN0000:       179 |         originalStatus: 200,
 YN0000: 

Impact:
While this test failure does not affect runtime behavior, it might introduce inconsistencies between the expected and actual error handling, potentially impacting robustness in error reporting.
This mismatch may cause confusion when debugging errors in production, as error messages are not formatted as expected.

@EskiMojo14
Copy link
Collaborator

I'm pretty sure the error message is dependent on your environment since it's thrown directly by JSON.parse.

I'd be tempted to just expect.stringContaining("SyntaxError") it to be honest.

@Adagedo
Copy link
Author

Adagedo commented Sep 19, 2024

I have suspicions on my environment though I was not too certain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants