https://github.com/smartlyio/objection-transactional-tests
Wrap Jest or Mocha tests in Objection transactions
https://github.com/smartlyio/objection-transactional-tests
objection-orm objectionjs
Last synced: about 1 year ago
JSON representation
Wrap Jest or Mocha tests in Objection transactions
- Host: GitHub
- URL: https://github.com/smartlyio/objection-transactional-tests
- Owner: smartlyio
- License: isc
- Created: 2018-09-20T13:12:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T14:41:35.000Z (over 2 years ago)
- Last Synced: 2024-04-14T06:24:40.308Z (about 2 years ago)
- Topics: objection-orm, objectionjs
- Language: TypeScript
- Size: 12.7 KB
- Stars: 13
- Watchers: 108
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Objection transactional tests
Run tests in [Jest](https://jestjs.io) or [Mocha](https://mochajs.org) in [Objection.js](http://vincit.github.io/objection.js/) transactions. This starts a new transaction at the beginning of each tests and does a rollback at the end of it, reverting the database to the state it was in before the test.
## Usage
```javascript
import { transactionPerTest } from "objection-transactional-tests";
describe("examples", () => {
transactionPerTest();
it("database interactions", () => {
// do something that touches database
});
});
```
Note that any database changes done in `beforeAll` won't be cleaned up.
The setup can be added to test setup script to apply it automatically for all
tests. This will ensure that no test pollute the test database, but also adds
overhead to tests that do not use the database.