Fix some property access issues

- Return `undefined` instead of throwing an error trying to access
  `libraryTypeID` on a Zotero.Feed -- this fixes a test failure with
  the latest Chai, which annoyingly runs inspect() on an object passed
  to .include() regardless of whether the test succeeds
- Make some deprecated properties non-enumerable to avoid unnecessary
  logging when the object is dumped
This commit is contained in:
Dan Stillman 2017-10-27 03:21:00 -04:00
parent 241df13954
commit e22d7a8459
5 changed files with 20 additions and 4 deletions

View file

@ -80,7 +80,8 @@ Zotero.defineProperty(Zotero.Collection.prototype, 'parent', {
set: function(val) {
Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2);
this.parentID = val;
}
},
enumerable: false
});
Zotero.defineProperty(Zotero.Collection.prototype, 'treeViewID', {

View file

@ -114,6 +114,11 @@ Zotero.defineProperty(Zotero.Feed.prototype, 'isFeed', {
Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypes', {
value: Object.freeze(Zotero.Feed._super.prototype.libraryTypes.concat(['feed']))
});
Zotero.defineProperty(Zotero.Feed.prototype, 'libraryTypeID', {
get: () => undefined
});
Zotero.defineProperty(Zotero.Feed.prototype, 'unreadCount', {
get: function() { return this._feedUnreadCount; }
});

View file

@ -105,7 +105,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'itemID', {
get: function() {
Zotero.debug("Item.itemID is deprecated -- use Item.id");
return this._id;
}
},
enumerable: false
});
Zotero.defineProperty(Zotero.Item.prototype, 'libraryID', {
get: function() { return this._libraryID; },
@ -2685,7 +2686,8 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentMIMEType', {
get: function() {
Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType");
return this.attachmentContentType;
}
},
enumerable: false
});
/**

View file

@ -142,7 +142,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', {
return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID);
default:
throw new Error(`Cannot return library type id for ${this._libraryType} library`);
throw new Error(`Tried to get library type id for ${this._libraryType} library`);
}
}
});
@ -169,6 +169,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'name', {
return Zotero.getString('pane.collections.library');
}
// This property is provided by the extending objects (Group, Feed) for other library types
throw new Error('Unhandled library type "' + this._libraryType + '"');
}
});

View file

@ -50,6 +50,13 @@ describe("Zotero.Feed", function() {
});
});
describe("#libraryTypeID", function () {
it("should be undefind", function* () {
let feed = yield createFeed();
assert.isUndefined(feed.libraryTypeID);
});
});
describe("#url", function() {
it("should throw if trying to set an invalid URL", function *() {
let feed = new Zotero.Feed({ name: 'Test ' + Zotero.randomString() });