以下测试是执行此操作的最佳方法,还是我可以改进它(并删除 Step 依赖项)?
我特别担心每个“步骤”函数都将前一次执行的测试与下一次执行的调用混为一谈。(即剪切粘贴易碎)
(另请参阅:如何按顺序执行异步 Mocha 测试(NodeJS)?)
it('should run an update', function(done) {
var db = new database.Database();
var sess = new session.Session(db);
Step(
function createTable() {
sess.exec('create table customers (id integer primary key auto_increment, name varchar, age integer)', this);
},
function insertCustomer1(err, message) {
assert(!err, err);
assert.equal("Table created.", message);
sess.exec('insert into customers (name, age) values ("james", 41)', this);
},
function insertCustomer2(err, message) {
assert(!err, err);
assert.equal("1 row inserted.", message);
sess.exec('insert into customers (name, age) values ("thomas", 19)', this);
},
function updateCustomer1(err, message) {
assert(!err, err);
assert.equal("1 row inserted.", message);
sess.exec('update customers set age = 42 where name = "james"', this);
},
function end(err, message) {
assert(!err, err);
assert.equal("1 row updated.", message);
done();
}
);
});