Created
November 19, 2020 15:24
-
-
Save shane-js/b1c182d3b493917a685135a88c3a57f2 to your computer and use it in GitHub Desktop.
Jasmine Tests: Using Transactions with ObjectionJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("can use a transaction for the current test and roll it back after", async function () { | |
const transactionForThisTest = await MyObjectionJsModel.startTransaction(); | |
spyOn(MyObjectionJsModel, "query") | |
.withArgs() | |
.and.callFake(() => MyObjectionJsModel.query(transactionForThisTest) as any) | |
.withArgs(transactionForThisTest) | |
.and.callThrough(); | |
const result = await someMethodThatChangesTheDatabaseState(); | |
expect(result).toEqual(1); | |
await transactionForThisTest.rollback(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment