Closed drnic closed 4 years ago
I agree that this is a bug, I think I can see why it wasn't running, it's because Jest expects a function so the runInTransaction
wrapper actually returns a function and doesn't run it.
Unfortunately, that means that a number of my tests weren't running either :disappointed:
I'm going to push up a fix to resolve this, for your case, you'll have to run the returned value, eg:
await runInTransaction(async () => {
console.log("create another User ... 2");
const user = User.create({ email });
await user.save();
const found = await User.findOne({
where: { email },
});
expect(found).toBeDefined();
expect(false).toBeTruthy();
})();
I've created a pull request here which resolves the issue (but it does require changes in your tests because you'll have to call the transactions you created). I apologise for the inconvenience this may have caused and I hope it didn't take up too much of your time!
Thanks for pointing it out :smile:
@Kerren-Entrostat 👍
I am reproducing an issue I found in my own code base -- code inside
await runInTransaction(async () => { ... })
does not fail its expectations; and it swallowsconsole.log
output. So perhaps the block insiderunInTransaction
is not running at all?This commit includes a failing test but the test suite doesn't fail.
The output I see is:
But I should also see
log inside runInTransaction
and the spec should not pass.Ideas?