I have the following tests where I am trying to exercise my db model against a sqlite in-memory database
describe(`task model`, () => {
let Task, sandbox;
beforeEach(() => (sandbox = createSandbox()));
afterEach(() => sandbox.restore());
beforeEach(async () => {
const dbConnection = new Sequelize(`sqlite::memory:`, { logging: false });
stub(dbConnectionModule, `dbConnection`).value(dbConnection);
Task = require(`./models/task.js`).Task;
await dbConnection.sync();
});
describe(`create a task`, () => {
let task;
beforeEach(async () => {
task = Task.build(taskData);
await task.save();
});
it(`gets an id`, () => expect(task.id).to.not.be.empty);
it(`shows up with a find all`, async () => {
const tasks = await Task.findAll();
expect(tasks).to.have.length(1);
});
});
});
I can verify the connection was new
ed up twice and yet my second test confusingly comes back with 2 tasks created.
It seems to be using the same db as on the first test!
I was under the impression that I would get a new in-memory db each time the Sequelize
constructor is called for sqlite's in-memory db, am I misunderstanding something?
Aucun commentaire:
Enregistrer un commentaire