Make itemFromCSLJSON independent of Zotero.Item existance.

Addresses !zotero/zotero-connectors#121"
This commit is contained in:
Adomas Venčkauskas 2017-05-07 17:05:08 +03:00
parent 746171ab78
commit dbeecb9b0a
2 changed files with 14 additions and 1 deletions

View file

@ -1815,7 +1815,7 @@ Zotero.Utilities = {
* @param {Object} cslItem
*/
"itemFromCSLJSON":function(item, cslItem) {
var isZoteroItem = item instanceof Zotero.Item,
var isZoteroItem = !!item.setType,
zoteroType;
// Some special cases to help us map item types correctly

View file

@ -384,6 +384,19 @@ describe("Zotero.Utilities", function() {
assert.equal(item.getField('title'), jsonAttachment.title, 'title imported correctly');
});
// For Zotero.Item created in translation sandbox in connectors
it("should not depend on Zotero.Item existing", function* () {
let item = new Zotero.Item;
var Item = Zotero.Item;
delete Zotero.Item;
assert.throws(() => "" instanceof Zotero.Item);
let data = loadSampleData('citeProcJSExport');
assert.doesNotThrow(Zotero.Utilities.itemFromCSLJSON.bind(Zotero.Utilities, item, Object.values(data)[0]));
Zotero.Item = Item;
assert.doesNotThrow(() => "" instanceof Zotero.Item);
})
});
describe("#ellipsize()", function () {