Check if attempting to use a legacy generator function in Mocha tests
This commit is contained in:
parent
ee777c5be6
commit
294f01bb3a
2 changed files with 9 additions and 7 deletions
|
@ -138,7 +138,7 @@ function Reporter(runner) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monkey-patch Mocha to check instanceof Error using compartent-local
|
// Monkey-patch Mocha to check instanceof Error using compartment-local
|
||||||
// Error object
|
// Error object
|
||||||
Mocha.Runner.prototype.fail = function(test, err){
|
Mocha.Runner.prototype.fail = function(test, err){
|
||||||
++this.failures;
|
++this.failures;
|
||||||
|
@ -168,6 +168,8 @@ mocha.setup({
|
||||||
Runnable.prototype.run = function (fn) {
|
Runnable.prototype.run = function (fn) {
|
||||||
if (this.fn.constructor.name === 'GeneratorFunction') {
|
if (this.fn.constructor.name === 'GeneratorFunction') {
|
||||||
this.fn = Zotero.Promise.coroutine(this.fn);
|
this.fn = Zotero.Promise.coroutine(this.fn);
|
||||||
|
} else if (typeof this.fn == 'function' && this.fn.isGenerator()) {
|
||||||
|
throw new Error("Attempting to use a legacy generator in Mocha test");
|
||||||
}
|
}
|
||||||
return run.call(this, fn);
|
return run.call(this, fn);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
describe("Zotero.Item", function () {
|
describe("Zotero.Item", function () {
|
||||||
describe("#getField()", function () {
|
describe("#getField()", function () {
|
||||||
it("should return false for valid unset fields on unsaved items", function* () {
|
it("should return false for valid unset fields on unsaved items", function () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
assert.equal(item.getField('rights'), false);
|
assert.equal(item.getField('rights'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false for valid unset fields on unsaved items after setting on another field", function* () {
|
it("should return false for valid unset fields on unsaved items after setting on another field", function () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.setField('title', 'foo');
|
item.setField('title', 'foo');
|
||||||
assert.equal(item.getField('rights'), false);
|
assert.equal(item.getField('rights'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false for invalid unset fields on unsaved items after setting on another field", function* () {
|
it("should return false for invalid unset fields on unsaved items after setting on another field", function () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.setField('title', 'foo');
|
item.setField('title', 'foo');
|
||||||
assert.equal(item.getField('invalid'), false);
|
assert.equal(item.getField('invalid'), false);
|
||||||
|
@ -19,7 +19,7 @@ describe("Zotero.Item", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#setField", function () {
|
describe("#setField", function () {
|
||||||
it("should throw an error if item type isn't set", function* () {
|
it("should throw an error if item type isn't set", function () {
|
||||||
var item = new Zotero.Item;
|
var item = new Zotero.Item;
|
||||||
assert.throws(item.setField.bind(item, 'title', 'test'), "Item type must be set before setting field data");
|
assert.throws(item.setField.bind(item, 'title', 'test'), "Item type must be set before setting field data");
|
||||||
})
|
})
|
||||||
|
@ -31,7 +31,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.ok(item.hasChanged());
|
assert.ok(item.hasChanged());
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should clear an existing field set to a falsy value", function () {
|
it("should clear an existing field set to a falsy value", function* () {
|
||||||
var field = 'title';
|
var field = 'title';
|
||||||
var fieldID = Zotero.ItemFields.getID(field);
|
var fieldID = Zotero.ItemFields.getID(field);
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
|
@ -76,7 +76,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.version, 1);
|
assert.equal(item.version, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should save versionNumber for computerProgram", function () {
|
it("should save versionNumber for computerProgram", function* () {
|
||||||
var item = new Zotero.Item('computerProgram');
|
var item = new Zotero.Item('computerProgram');
|
||||||
item.setField("versionNumber", "1.0");
|
item.setField("versionNumber", "1.0");
|
||||||
var id = yield item.saveTx();
|
var id = yield item.saveTx();
|
||||||
|
|
Loading…
Add table
Reference in a new issue