commit dbf47a3e1e6896a5a7729b2f48c0d94534562141
parent 3ad15f7b59482d1f0fb26665ba2a55c6450b1360
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 2 Jun 2015 15:14:06 -0400
Merge pull request #751 from aurimasv/tests-legacy_generators
Check if attempting to use a legacy generator function in Mocha tests
Diffstat:
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/test/content/runtests.js b/test/content/runtests.js
@@ -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
Mocha.Runner.prototype.fail = function(test, err){
++this.failures;
@@ -168,6 +168,8 @@ mocha.setup({
Runnable.prototype.run = function (fn) {
if (this.fn.constructor.name === 'GeneratorFunction') {
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);
};
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -1,17 +1,17 @@
describe("Zotero.Item", 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');
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');
item.setField('title', 'foo');
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');
item.setField('title', 'foo');
assert.equal(item.getField('invalid'), false);
@@ -19,7 +19,7 @@ describe("Zotero.Item", 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;
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());
})
- 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 fieldID = Zotero.ItemFields.getID(field);
var item = new Zotero.Item('book');
@@ -76,7 +76,7 @@ describe("Zotero.Item", function () {
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');
item.setField("versionNumber", "1.0");
var id = yield item.saveTx();