Miguelmo
Miguelmo

Reputation: 41

How to test Sequelize in nestjs model

How can I test the Sequelize param, like

    constructor(
        private sequelize: Sequelize,
        @InjectModel(User) private userModel: typeof User,
        @InjectModel(Shop) private shopModel: typeof Shop
     ) {}

for the models I use

    { provide: getModelToken(User), useValue: User },
    { provide: getModelToken(Shop), useValue: Shop },

How can I add Sequelize as provider?

It gives me this error:

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

Upvotes: 2

Views: 1818

Answers (1)

Miguelmo
Miguelmo

Reputation: 41

Ok, I have found the solution, you just have to add this to the provider

{
  provide: Sequelize,
  useValue: sequelizeMock
}

Upvotes: 2

Related Questions