Skip to content

[NEW TEST] Sequelize transactions #1985

@c-kirkeby

Description

@c-kirkeby

Is there an existing issue for this?

  • I have searched the existing issues

Feature Test To Be Requested

The sequelize-sample is really awesome, but we're using Sequelize Transactions in our codebase and by doing so we have to mock the Sequelize transaction() method or Nest will throw dependency errors:

Nest can't resolve dependencies of the CatService (CatEntityRepository, ?). Please make sure that the argument Sequelize at index [5] is available in the RootTestModule context.

Potential solutions:
- Is RootTestModule a valid NestJS module?
- If Sequelize is a provider, is it part of the current RootTestModule?
- If Sequelize is exported from a separate @Module, is that module imported within RootTestModule?
  @Module({
    imports: [ /* the Module containing Sequelize */ ]
  })

I've looked through the NestJS documentation and Discord but I couldn't find any good examples of how to do this because if I mock the Sequelize transaction like this, I don't get the value from my service call:

        {
          provide: Sequelize,
          useValue: {
            transaction: jest.fn(() => Promise.resolve()),
          },
        },

The Nest docs state to use a helper factory class but I couldn't find a good example of this either.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions