BlinkUX / sequelize-mock

A simple mock interface specifically for testing code relying on Sequelize models
https://sequelize-mock.readthedocs.io
MIT License
139 stars 73 forks source link

Is this library compatible with models defined by Sequelize-Typescript? #90

Open pandrews-hdai opened 3 years ago

pandrews-hdai commented 3 years ago

Now that I've spent the better part of a week debugging various issues and trying to find examples for injecting mocked models into repositories and just not having any luck getting sequelize to accept the mocks and even complete testing module initialization...I'm beginning to wonder if this library just can't be used with models defined as classes with decorators from sequelize-typescript?

First I was getting a lot of Model not initialized: MyModel cannot be instantiated. "MyModel" needs to be added to a Sequelize instance.

But in attempting to actually do that I started getting TypeError: this.lib.Database is not a constructor, which seems like it's coming out of the sequelize code itself trying to use a real ConnectionManager rather than the validation-only fake ConnectionManager and Dialect I setup using a Sequelize class imported from sequelize-typescript.

Is it possible that mocked models provided by this library just don't know about the wrappers provided by sequelize-typescript and are trying to use sequelize directly but can't?

redevill commented 3 years ago

Struggling with the same issue - sequelize-typescript with repository mode, and trying to mock out sequelize repository objects. Seems to be far more info out there on Integration testing (Using supertest with a test database, and leveraging sequelize cli to reset the database with each test.) rather than unit test of just the API handler function.