Closed oojikoo closed 2 years ago
Okay, I was able to recreate this in a truly minimum fashion, no deps other than Nest. You can find the repo here and run pnpm i && pnpm test:e2e
(yarn and npm of course work too).
I believe the issue comes from the ModulesContainer
class where this.applicationId = v4()
. If every module container gets the same application id, (due to mocking the return value of v4()
) then it could be problematic. I don't know if there's anything Nest could do about this other than give a warning in the docs about not making a blanket mock for uuid.v4()
or possibly trying to keep a track of all application ids and throwing an error if a duplicate comes up
thanks! I should probably set default uuid value for entity id from database layer, not from application layer.
also, using 3rd-party libs like this
make things a bit harder to test :/
Nest internally relies on the uuid package so if you mock it to return a constant value it will surely have a negative impact on the framework's behavior. If you feel like we should add a hint about that in the docs, please, create a PR to the docs! Contributions are more than welcome
Is there an existing issue for this?
Current behavior
using nestjs, nx, ogma when run nx test , I'm seeing this
withthis line commented, all tests pass...
apps/payment-svc/test/payment.spec.ts
jest.mock('uuid', () => ({ v4: () => '00000000-0000-0000-0000-000000000000' }));
Minimum reproduction code
https://github.com/oojikoo/ogma-jest
Steps to reproduce
setup postgresql for testing
update all db credential and info for testing
yarn
nx test payment-svc --verbose --detectOpenHandles
Expected behavior
even with uuid mocking, tests should be passed
Package
Other package
@ogma/nestjs-module,
NestJS version
7.1.0
Packages versions
Node.js version
v16.13.1
In which operating systems have you tested?
Other
No response