Unit Testing with Transactions

Typically in our Unit Tests, we have something like...
describe('test suite', () => {
  let tx: Transaction;
  beforeEach(() => {
    tx = db.getConnection();
  })
  afterEach(() => {
    tx.rollback();
  })
  it('test', async () => {
    const result = await tx.makeSomeDbChanges();
    expect(result).toBe(something);
  })


Does Drizzle have a mechanism for getting access to the transaction without the anonymous function route? I'd prefer not to do the following in every test...

describe('test suite', () => {
  it('test', async () => {
    const db = drizzle(conn);
    db.transaction( async (tx) => {
      const result = await tx.makeSomeDbChanges();
      expect(result).toBe(something);
      tx.rollback();
    }); 
  })
}

Especially when I have to throw in error handling because tx.rollback() throws an Error and doesn't simply rollback.

What are others doing for unit testing?
Was this page helpful?