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
Jest mock timer warning without using fake timers #12514
Comments
cannot reproduce, this must mean that mock timers are somehow enabled in your tests OR you are not using NodeJS (like deno) and that function somehow does not include the line checking for mongoose/lib/helpers/printJestWarning.js Line 12 in 94b308e
which i cant get to output anything other than 9 (
from what i can tell that version does not exist yet |
Sorry I was looking at the wrong MongoDB version, I'm using But thanks for the code reference, I was able to narrow down the root cause:
Using winston logger with this option causes the output of
Is it correct for printJestWarning to always output a warning if |
I created a PR for what I think the correct fix might be, but feel free to close it if this is not the right solution. |
fix: make Jest fake timers check more robust to other libs that overwrite time functions
Prerequisites
Mongoose version
6.6.0
Node.js version
18.7.0
MongoDB server version
6.5.4
Description
Using
jest.spyOn
shows the following warning in the console:(node:35252) [MONGOOSE] Warning: Mongoose: looks like you're trying to test a Mongoose app with Jest's mock timers enabled. Please make sure you read Mongoose's docs on configuring Jest to test Node.js apps: https://mongoosejs.com/docs/jest.html
Steps to Reproduce
Create a test with the following:
jest.spyOn(logger, 'error').mockImplementation(() => ({} as Logger));
For additional context: https://github.com/sspenst/pathology/blob/main/tests/pages/api/avatar/avatar.test.ts#L23
Expected Behavior
No warning should appear in the console.
The text was updated successfully, but these errors were encountered: