Answer the question
In order to leave comments, you need to log in
How to test jest + sequelize?
Good afternoon, I'm groaning trying to write integration tests.
When it came to the database, there were problems, because sequelize.sync({ force: true });
sometimes it works, sometimes it doesn’t, randomly.
Now the test files look like this:
const CategoryModel = require('../CategoryModel'); // sequelize model
beforeAll(async () => {
await CategoryModel.sync({ force: true });
await CategoryModel.bulkCreate([ /* массив данных для вставки */ ]);
});
// далее сами тесты ...
1. bulkCreate() - [SequelizeDatabaseError]: Table 'shop_test.categories' does not exist
2. bulkCreate() - [SequelizeUniqueConstraintError]: Validation error. (Duplicate entry 'spoons' for key 'categories.slug')
"test": "jest --runInBand --detectOpenHandles"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question