誓言:testingasynchronous交织

有没有一种方法来testing(潜在的)与asynchronous函数交叉誓言?

例如:

// Topic portion var user = new User('jacob') user.set('email,'foo@bar.com') user.save() // a user.set('email',derp@cherp.com') user.save() // b user.refresh(this.callback) // Reload from database // Callback assert.equals(user.email,'derp@cherp.com') 

这两个节省之间可能会有一个竞赛条件。 在编写我的testing时,我想确保我的API确保b完成最后(并且我们拥有正确的电子邮件最终值)。 随着写作的方式,testing将在一些巧合的时间通过。

下面是来自誓言文档的例子:

嵌套的上下文充当嵌套的callback,并将返回parameter passing给下一个上下文。

文档: http : //vowsjs.org/

 { topic: function () { fs.stat('~/FILE', this.callback); }, 'after a successful `fs.stat`': { topic: function (stat) { fs.open('~/FILE', "r", stat.mode, this.callback); }, 'after a successful `fs.open`': { topic: function (fd, stat) { fs.read(fd, stat.size, 0, "utf8", this.callback); }, 'we can `fs.read` to get the file contents': function (data) { assert.isString (data); } } } }