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

Enforce no unmocked API calls in the jest tests... somehow? #19187

Open
jmchilton opened this issue Nov 22, 2024 · 0 comments
Open

Enforce no unmocked API calls in the jest tests... somehow? #19187

jmchilton opened this issue Nov 22, 2024 · 0 comments

Comments

@jmchilton
Copy link
Member

Sometimes these blow up in really clear ways but sometimes they don't. Take for instance - 21b8b9e. I just noticed the output in the logs:

(node:78457) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

which I think is a warning they are dropping or have dropped in newer node versions. But based on that I added the server mock. After that, I got the very clear message:

  Cannot log after tests are done. Did you forget to wait for something async in your test?
    Attempted to log "{
      name: 'Error',
      message: '\n' +
        'No request handler found for GET http://localhost/api/users/current/usage.\n' +
        '\n' +
        'Make sure you have added a request handler for this request in your tests.\n' +
        '\n' +
        'Example:\n' +
        '\n' +
        'const { server, http } = useServerMock();\n' +
        'server.use(\n' +
        "    http.get('/api/users/current/usage', ({ response }) => {\n" +
        '        return response(200).json({});\n' +
        '    })\n' +
        ');\n' +

It would be great if I just got by default when running a jest test I think and then ideally failing the tests on any unmocked API calls.

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

1 participant