[](https://app.travis-ci.com/github/viniciusjssouza/typeorm-transactional-tests) [

TypeORM does not provide builtin transactional tests. If your tests write to a non in-memory database, probably you have to truncate
or erase all your tables for every test case.
This package allows the creation of transactional contexts during the test, starting a transaction in the begining of the test
and rolling back at the end. This is a faster solution than truncate/delete, once nothing is really written to disk.
bash
npm install --save-dev typeorm-transactional-tests
`$3
Versions 1.x.x of this library is compatible with typeorm 0.2.xVersions 2.x.x of this library is compatible with typeorm 0.3.x
$3
#### Jest
To apply the transactional context with Jest, just start the context in an
beforeEach block and finish it in an afterEach:
`typescript
import {Connection, getConnection } from 'typeorm';
import { TransactionalTestContext } from 'typeorm-transactional-tests';let connection: Connection;
let transactionalContext: TransactionalTestContext;
beforeEach(async () => {
connection = getConnection();
transactionalContext = new TransactionalTestContext(connection);
await transactionalContext.start();
});
afterEach(async () => {
await transactionalContext.finish();
});
`Also, it is possible to apply the context to all your tests using a global Jest setup file. Add a new file on your test folder:
`typescript
import TransactionalTestContext from 'typeorm-transactional-tests'// @ts-ignore
global.beforeEach(async () => await transactionalContext.start());
// @ts-ignore
global.afterEach(async () => await transactionalContext.finish());
`
And point the Jest configuration to it:
`json
"setupFilesAfterEnv": [
"/test/support/transactionalContext.ts"
]
``