Enable Bluebird generator support in Mocha
Promise-yielding ES6 generator functions can now be used for test functions, and they'll automatically be wrapped with Bluebird's coroutine().
This commit is contained in:
parent
384a547693
commit
973e602cfc
|
@ -66,6 +66,19 @@ function Reporter(runner) {
|
||||||
|
|
||||||
// Setup Mocha
|
// Setup Mocha
|
||||||
mocha.setup({ui:"bdd", reporter:Reporter});
|
mocha.setup({ui:"bdd", reporter:Reporter});
|
||||||
|
|
||||||
|
// Enable Bluebird generator support in Mocha
|
||||||
|
(function () {
|
||||||
|
var Runnable = Mocha.Runnable;
|
||||||
|
var run = Runnable.prototype.run;
|
||||||
|
Runnable.prototype.run = function (fn) {
|
||||||
|
if (this.fn.constructor.name === 'GeneratorFunction') {
|
||||||
|
this.fn = Zotero.Promise.coroutine(this.fn);
|
||||||
|
}
|
||||||
|
return run.call(this, fn);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
var assert = chai.assert,
|
var assert = chai.assert,
|
||||||
expect = chai.expect;
|
expect = chai.expect;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
describe("Support Functions for Unit Testing", function() {
|
describe("Support Functions for Unit Testing", function() {
|
||||||
describe("resetDB", function() {
|
describe("resetDB", function() {
|
||||||
it("should restore the DB to factory settings", Zotero.Promise.coroutine(function* () {
|
it("should restore the DB to factory settings", function* () {
|
||||||
this.timeout(30000);
|
this.timeout(30000);
|
||||||
yield Zotero.Items.erase(1);
|
yield Zotero.Items.erase(1);
|
||||||
assert.isFalse(yield Zotero.Items.getAsync(1));
|
assert.isFalse(yield Zotero.Items.getAsync(1));
|
||||||
|
@ -9,6 +9,6 @@ describe("Support Functions for Unit Testing", function() {
|
||||||
assert.isObject(item);
|
assert.isObject(item);
|
||||||
yield item.loadItemData();
|
yield item.loadItemData();
|
||||||
assert.equal(item.getField("url"), "https://www.zotero.org/support/quick_start_guide");
|
assert.equal(item.getField("url"), "https://www.zotero.org/support/quick_start_guide");
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user