Skip to content

Commit

Permalink
fix(observer): respect non-enumerable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktim committed May 16, 2016
1 parent bb40575 commit ff8f9c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/property-observation.js
Expand Up @@ -96,7 +96,8 @@ export class SetterObserver {

if (!Reflect.defineProperty(this.obj, this.propertyName, {
configurable: true,
enumerable: true,
enumerable: this.propertyName in this.obj ?
this.obj.propertyIsEnumerable(this.propertyName) : true,
get: this.getValue.bind(this),
set: this.setValue.bind(this)
})) {
Expand Down
18 changes: 18 additions & 0 deletions test/observer-locator.spec.js
Expand Up @@ -53,6 +53,24 @@ describe('ObserverLocator', () => {
expect(Logger.prototype.warn).toHaveBeenCalledWith('Cannot observe property \'bar\' of object', obj);
});

it('respects the enumerability in the SetterObserver', () => {
var obj = {};
Object.defineProperties(obj, {
'foo': {
configurable: true,
enumerable: true
},
'bar': {
configurable: true,
enumerable: false
}
});
['foo', 'bar', 'baz'].forEach(prop => {
locator.getObserver(obj, prop).convertProperty();
});
expect(Object.keys(obj)).toEqual(['foo', 'baz']);
});

it('uses ValueAttributeObserver for element value attributes', () => {
var obj = createElement('<input />'),
observer = locator.getObserver(obj, 'value');
Expand Down

0 comments on commit ff8f9c7

Please sign in to comment.