typeorm-transactional
typeorm-transactional copied to clipboard
Unit Test Mocking doesn't work
[x] NestJS [x] TypeORM
I have use jest to test function with Transactional decorator then I following these step to mock transaction for unit test mocking and get error from jest with message
No storage driver defined in your app ... please call initializeTransactionalContext() before application start.
Do anyone have any solution to resolve this issue?
~~Running into the same issue @Aliheym~~
EDIT: Looks like someone already figured this out.
I updated
jest.mock('typeorm-transactional', () => ({
Transactional: () => () => ({}),
}));
with
jest.mock("typeorm-transactional", () => ({
Transactional: () => () => ({}),
runOnTransactionCommit: () => () => ({}),
runOnTransactionRollback: () => () => ({}),
runOnTransactionComplete: () => () => ({}),
initializeTransactionalContext: () => ({}), // seems to be required for testing
}));
And my tests are passing :heavy_check_mark: