Skip to content

Instantly share code, notes, and snippets.

@fupslot
Created July 23, 2015 09:21
Show Gist options
  • Save fupslot/11086be90835ee539e46 to your computer and use it in GitHub Desktop.
Save fupslot/11086be90835ee539e46 to your computer and use it in GitHub Desktop.
it('Property', inject(function($parse){
function Property(context, fieldName) {
this.$getter = $parse(fieldName);
this.$setter = this.$getter.assign;
this.$context = context;
}
Property.prototype.get = function() {
return this.$getter(this.$context);
};
Property.prototype.set = function(value) {
this.$setter(this.$context, value);
return this.get();
};
var member = {address: {city: {district: null}}};
var district = new Property(member, 'address.city.district');
expect(district.get()).toEqual(null);
expect(district.set('Eugene')).toEqual('Eugene');
expect(district.get()).toEqual('Eugene');
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment