Replies: 5 comments 9 replies
-
Apparently, jest is doing some mocking of the Pretty much the same issue in another library: Will take a closer look later today, maybe there is something we can do, but this seems to be more of a jest issue. |
Beta Was this translation helpful? Give feedback.
-
A potential workaround might be to add a |
Beta Was this translation helpful? Give feedback.
-
One thing I have not tried yet is disabling |
Beta Was this translation helpful? Give feedback.
-
I'm weirdly getting this only when I run tests in vscode, but not when I run jest from the cmdline. Here is my config:
What could be the difference between the two? |
Beta Was this translation helpful? Give feedback.
-
I dug into this a bit more and the problem seems to come when MikroORM clones the entity metadata after Jest (presumably) has mocked it. The clone method in @mikro-orm/core/utils/clone.js doesn't recognise that a Map is a Map and so clones it like a plain object. I was able to workaround this by clearing the cached metadata in the global setup script so that it is re-created rather than using the cached (mocked) version. e.g.
Obviously this doesn't help with the original problem of wanting to cache the metadata, but might help people who want to do other stuff in the global setup (in my case it was to start a testcontainer and run migrations). |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
When adding a basic global setup script to jest, the global setup file will run fine:
However, we get an error in running
await MikroORM.init()
in testing suites immediately after. This did not used to happen, and I am unsure if this is due to an update to Jest or to MikroORM. Removing the call toMikroORM.init()
in the global setup resolves the issue.Stack trace
Additional context
Here is a repo that can be used to duplicate the issue.
To Reproduce
Steps to reproduce the behavior:
src/database/foo/foo.service.spec.ts
in the provided repoExpected behavior
Global setup should run fine, and create the
.ts
cache. Then, all tests should run.Versions
Beta Was this translation helpful? Give feedback.
All reactions