Anybody here used prisma in e2e tests with time mo...
# orm-help
p
Anybody here used prisma in e2e tests with time mocking from sinonjs? I always get an error after advancing mocked time with e.g.
await clock.tickAsync(10000)
I need to mock time to test for cases like correct token expirations etc. Is there something like a timeout in prisma or anything that could cause this error? StackTrace:
Copy code
TypeError: Cannot read property 'paused' of undefined

    at onBodyTimeout (/home/patrick/Code/xxx/server/node_modules/@prisma/client/runtime/index.js:24829:16)
    at callTimer (/home/patrick/Code/xxx/server/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:423:24)
    at doTickInner (/home/patrick/Code/xxx/server/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:894:29)
    at Immediate.nextPromiseTick (/home/patrick/Code/xxx/server/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:955:25)
    at processImmediate (internal/timers.js:461:21)
    at process.topLevelDomainCallback (domain.js:144:15)
    at process.callbackTrampoline (internal/async_hooks.js:129:14)
r
@Patrick 👋 Not sure of this, but where exactly are you calling
tickAsync
?
p
Im calling it in a jest e2e test case like this:
Copy code
const token = await getTokenFromMail(mailhog, registerEmail, TokenType.ACTIVATION);
await clock.tickAsync((tokenService.activationTokenExpiration * 60 * 1000) + 100);

const activationResponse = await app.inject().post('/auth/activate').body(new TokenResponseDto({ token }));
Its erroring after calling tickAsync, even before calling the app route itself
r
So to test this I could add it under any
test
block right?
I’ll try to reproduce this.
p
Yes
I'm using the timer only package from sinon:
import FakeTimers from '@sinonjs/fake-timers';
👍 1
Maybe worth mentioning too: I am using prisma with NestJS. So I bootstrap a NestJS app to call my routes like described in the NestJS test documentation. This is probably initializing a DB connection with prisma and probably things getting out of hand with mocking the time.