不要怂,就是干,撸起袖子干!

Commit 21074872 by Mick Hansen

feat(promises): example of better(?) test

1 parent c9368843
Showing with 17 additions and 21 deletions
...@@ -1331,28 +1331,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1331,28 +1331,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Worker.hasMany(Task, { through: WorkerTasks }) Worker.hasMany(Task, { through: WorkerTasks })
Task.hasMany(Worker, { through: WorkerTasks }) Task.hasMany(Worker, { through: WorkerTasks })
this.sequelize.sync().done(function(err) { // Test setup
expect(err).not.to.be.ok this.sequelize.sync().then(function() {
Worker.create({}).done(function (err, worker) { return Sequelize.Promise.all([
expect(err).not.to.be.ok Worker.create({}),
Task.bulkCreate([{}, {}]).done(function (err) { Task.bulkCreate([{}, {}]).then(function () {
expect(err).not.to.be.ok return Task.findAll()
Task.findAll().done(function (err, tasks) {
expect(err).not.to.be.ok
worker.setTasks(tasks).done(function () {
worker.removeTask(tasks[0]).done(function (err) {
expect(err).not.to.be.ok
worker.getTasks().done(function (err, tasks) {
expect(tasks.length).to.equal(1)
done()
})
})
})
})
}) })
}) ]);
}) }).spread(function (worker, tasks) {
// Set all tasks, then remove one tasks, then return all tasks
return worker.setTasks(tasks).then(function () {
return worker.removeTask(tasks[0]);
}).then(function () {
return worker.getTasks();
});
}).then(function (tasks) {
expect(tasks.length).to.equal(1);
}).then(done.bind(null, null), done);
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!