Sha256: ba2e2e792b9b6f6fae5af0d2c96d447b873c8cc91620543f2a4a5808fd2945bf
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
/*! * Chai - addProperty utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ var config = require('../config'); var flag = require('./flag'); /** * ### 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 * @namespace Utils * @name addProperty * @api public */ module.exports = function (ctx, name, getter) { Object.defineProperty(ctx, name, { get: function addProperty() { var old_ssfi = flag(this, 'ssfi'); if (old_ssfi && config.includeStack === false) flag(this, 'ssfi', addProperty); var result = getter.call(this); return result === undefined ? this : result; } , configurable: true }); };
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
mdarray-sol-0.1.0-java | node_modules/chai/lib/chai/utils/addProperty.js |
select_all-rails-0.3.1 | node_modules/chai/lib/chai/utils/addProperty.js |