Fix clearing of missing fields in Item::fromJSON()

This commit is contained in:
Dan Stillman 2016-07-18 19:56:50 -04:00
parent 35d057decb
commit 7b45b920fc
2 changed files with 31 additions and 9 deletions

View file

@ -1194,8 +1194,25 @@ describe("Zotero.Item", function () {
});
})
})
describe("#fromJSON()", function () {
it("should clear missing fields", function* () {
var item = new Zotero.Item('book');
item.setField('title', 'Test');
item.setField('date', '2016');
item.setField('accessDate', '2015-06-07T20:56:00Z');
yield item.saveTx();
var json = item.toJSON();
// Remove fields, which should cause them to be cleared in fromJSON()
delete json.date;
delete json.accessDate;
item.fromJSON(json);
assert.strictEqual(item.getField('title'), 'Test');
assert.strictEqual(item.getField('date'), '');
assert.strictEqual(item.getField('accessDate'), '');
});
it("should ignore unknown fields", function* () {
var json = {
itemType: "journalArticle",