Throw an error if item type isn't set when saving

And add a test for throwing from setField(), which already happens.
This commit is contained in:
Dan Stillman 2015-05-06 04:16:54 -04:00
parent 7879e5432a
commit 26e1372f46
2 changed files with 10 additions and 2 deletions

View File

@ -781,7 +781,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
let itemTypeID = this.itemTypeID;
if (!itemTypeID) {
throw ('Item type must be set before setting field data');
throw new Error('Item type must be set before setting field data');
}
var fieldID = Zotero.ItemFields.getID(field);
@ -1173,7 +1173,10 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
var options = env.options;
var itemTypeID = this.itemTypeID;
if (!itemTypeID) {
throw new Error("Item type must be set before saving");
}
var sqlColumns = [];
var sqlValues = [];
var reloadParentChildItems = {};

View File

@ -19,6 +19,11 @@ describe("Zotero.Item", function () {
});
describe("#setField", 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");
})
it("should mark a field as changed", function () {
var item = new Zotero.Item('book');
item.setField('title', 'Foo');