Skip to content

Instantly share code, notes, and snippets.

@shane-js
Created November 19, 2020 15:24
Show Gist options
  • Save shane-js/b1c182d3b493917a685135a88c3a57f2 to your computer and use it in GitHub Desktop.
Save shane-js/b1c182d3b493917a685135a88c3a57f2 to your computer and use it in GitHub Desktop.
Jasmine Tests: Using Transactions with ObjectionJS
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