我在尝试设置用于测试目的的数据库时遇到了一些麻烦。应删除存储在数据库中的数据,并为每个测试重新填充。我目前正在做以下事情:
数据库.js
const mongoose = require('mongoose');
// a Mongoose model describing an entity
const Entity = require('entity-model');
// entities.mock is an array containing entity objects.
const mockedEntities= require('./entities.mock');
function setUp() {
Entities.collection.insertMany(mockedEntities);
}
function breakDown() {
mongoose.connection.on('connected', () => {
mongoose.connection.db.dropDatabase();
});
}
module.exports = { setUp, breakDown };
然后在我的test.js 中:
const db = require('./db');
describe('e2e tests to make sure all endpoints return the correct data from the database', () => {
beforeEach(async () => {
await db.breakDown();
db.setUp();
});
it('should check store-test-result (UR-101)', (done) => ...perform test);
it('should check store-nirs-device (UR-102)', (done) => ...perform test);
});
在正确重新填充数据库之前,我似乎没有清空数据库。关于可能是什么原因的任何建议?
拉莫斯之舞
相关分类