Closed DimosthenisK closed 1 year ago
Is it possible that you don't (completely) await
all functions that call queries in your test? e.g. something like this
async function firstTest() {
// ...
const user = userService.loadUserFromDb(3); // note the missing "await"
}
async function secondTest() {
// This test will fail now
}
where userService.loadUserFromDb
looks like this:
public async loadUSerFromDb(id: number) {
const user = await this.prismaService.user.findUnique({ where: { id } }); // note the "await" here
return user;
}
I did publish a new pre-release version which improves the robustness of savepoint handling and logs a warning if the case mentioned above is detected. You can install it using
npm i -D @chax-at/transactional-prisma-testing@1.0.1-rc.1
This version fixes my own reproduction example from above at least (and logs a warning), please tell me if it's working for you as well (or maybe throws a different error at least).
The fix I mentioned above landed in 1.1.0, if you have time, you can try it out. Otherwise, you can stay on 0.6.0 which doesn't have implicit query transaction/savepoints (in case you don't need it and don't want to deal with debugging).
I'll close the issue for now, assuming it's fixed - but please let me know if you're still encountering any issues with the new version! (I don't know if you can re-open the issue, but just comment here or open another issue in this case if re-opening doesn't work)
I'm not quite sure what happened, but exactly the same code throws an error in v1 and doesn't in v0.5.0, using prisma v4.15.0. Happened in two different projects that use this library.
This is the code that builds the tests: