Sha256: 95c53d7ba17d03c5066350be2b6a50cbd8c6143f0c9f0152b02a5e14cd63ede3
Contents?: true
Size: 1.02 KB
Versions: 100
Compression:
Stored size: 1.02 KB
Contents
/*! * Chai - addProperty utility * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /** * ### addProperty (ctx, name, getter) * * Adds a property to the prototype of an object. * * utils.addProperty(chai.Assertion.prototype, 'foo', function () { * var obj = utils.flag(this, 'object'); * new chai.Assertion(obj).to.be.instanceof(Foo); * }); * * Can also be accessed directly from `chai.Assertion`. * * chai.Assertion.addProperty('foo', fn); * * Then can be used as any other assertion. * * expect(myFoo).to.be.foo; * * @param {Object} ctx object to which the property is added * @param {String} name of property to add * @param {Function} getter function to be used for name * @name addProperty * @api public */ module.exports = function (ctx, name, getter) { Object.defineProperty(ctx, name, { get: function () { var result = getter.call(this); return result === undefined ? this : result; } , configurable: true }); };
Version data entries
100 entries across 68 versions & 1 rubygems