RequestContext.currentContext.req is undefined
Hi When running the test code in the unit jest environment, the RequestContext.currentContext.req in req property remains undefined.
You can use something like this
jest.mock('nestjs-request-context', () => ({ RequestContext: { currentContext: { req: { user: {}, }, }, }, }));
and then in test suite, just mock the currentContext.req to what you want
RequestContext.currentContext.req.user = ....;
It's my case with mocking user, but you can use it as you want
just mock the currentContext.req to what you want
@sebastian-xicay - how do you access this to mock it?
just mock the currentContext.req to what you want
@sebastian-xicay - how do you access this to mock it?
I've attached the example
jest.mock('nestjs-request-context', () => ({
RequestContext: {
currentContext: {
req: {
user: {},
},
},
},
}));
Oh. But you said 'and then in test suite, just mock the currentContext.req to what you want' - I assumed there was some future mocking beyond what you're saying here @sebastian-xicay
Anyway, I found my problem - it was caused by not have my extended prisma client used in my tests.