Improve LRUCache containsKey test, thanks @tschaub
This commit is contained in:
@@ -91,7 +91,7 @@ ol.structs.LRUCache.prototype.clear = function() {
|
|||||||
* @return {boolean} Contains key.
|
* @return {boolean} Contains key.
|
||||||
*/
|
*/
|
||||||
ol.structs.LRUCache.prototype.containsKey = function(key) {
|
ol.structs.LRUCache.prototype.containsKey = function(key) {
|
||||||
return key in this.entries_;
|
return this.entries_.hasOwnProperty(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -99,11 +99,38 @@ describe('ol.structs.LRUCache', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setting a disallowed key', function() {
|
describe('disallowed keys', function() {
|
||||||
it('raises an exception', function() {
|
it('setting raises an exception', function() {
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('constructor', 0);
|
||||||
|
}).toThrow();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
lruCache.set('hasOwnProperty', 0);
|
lruCache.set('hasOwnProperty', 0);
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('isPrototypeOf', 0);
|
||||||
|
}).toThrow();
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('propertyIsEnumerable', 0);
|
||||||
|
}).toThrow();
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('toLocaleString', 0);
|
||||||
|
}).toThrow();
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('toString', 0);
|
||||||
|
}).toThrow();
|
||||||
|
expect(function() {
|
||||||
|
lruCache.set('valueOf', 0);
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
it('getting returns false', function() {
|
||||||
|
expect(lruCache.containsKey('constructor')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('hasOwnProperty')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('isPrototypeOf')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('propertyIsEnumerable')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('toLocaleString')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('toString')).toBeFalsy();
|
||||||
|
expect(lruCache.containsKey('valueOf')).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user