it('should bind to the object', function() { ko.defineComputedProperty(obj, 'fullName', function() { return this.firstName + ' ' + this.lastName }) obj.fullName.should.equal('Bob Doe') })
it('should define a property with only a getter as the computed', function() { ko.defineComputedProperty(obj, 'fullName', function() { return this.firstName + ' ' + this.lastName }) var propDescriptor = Object.getOwnPropertyDescriptor(obj, 'fullName') propDescriptor.get.should.be.an.observable should.not.exist(propDescriptor.set) })
it('should define a property with both a get and set', function() { var val = ko.observable('value') ko.defineComputedProperty(obj, 'writable', { write: x => val(x), read: () => JSON.stringify(val()) }) var propDescriptor = Object.getOwnPropertyDescriptor(obj, 'writable') propDescriptor.get.should.be.an.observable propDescriptor.set.should.be.an.observable obj.writable.should.equal('"value"') obj.writable = 'newvalue' obj.writable.should.equal('"newvalue"') })