galaxyproject / galaxy

Data intensive science for everyone.
https://galaxyproject.org
Other
1.42k stars 1.01k forks source link

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

Open jmchilton opened 6 days ago

jmchilton commented 6 days ago

Sometimes these blow up in really clear ways but sometimes they don't. Take for instance - https://github.com/galaxyproject/galaxy/pull/19186/commits/21b8b9e41adbe00d642f594eedbd8b82e171438f. 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.