Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Mocking doesn't work #50

Open
icbrg opened this issue Feb 21, 2024 · 1 comment
Open

Unit Test Mocking doesn't work #50

icbrg opened this issue Feb 21, 2024 · 1 comment

Comments

@icbrg
Copy link

icbrg commented Feb 21, 2024

[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?

@xadamxk
Copy link

xadamxk commented Mar 19, 2024

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 ✔️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants