How to use assertOwnPropertyDescriptor method in chai

Best JavaScript code snippet using chai

assertions.js

Source:assertions.js Github

copy

Full Screen

1/*!2 * chai3 * http://chaijs.com4 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>5 * MIT Licensed6 */7module.exports = function (chai, _) {8 var Assertion = chai.Assertion9 , toString = Object.prototype.toString10 , flag = _.flag;11 /**12 * ### Language Chains13 *14 * The following are provided as chainable getters to15 * improve the readability of your assertions. They16 * do not provide testing capabilities unless they17 * have been overwritten by a plugin.18 *19 * **Chains**20 *21 * - to22 * - be23 * - been24 * - is25 * - that26 * - which27 * - and28 * - has29 * - have30 * - with31 * - at32 * - of33 * - same34 *35 * @name language chains36 * @api public37 */38 [ 'to', 'be', 'been'39 , 'is', 'and', 'has', 'have'40 , 'with', 'that', 'which', 'at'41 , 'of', 'same' ].forEach(function (chain) {42 Assertion.addProperty(chain, function () {43 return this;44 });45 });46 /**47 * ### .not48 *49 * Negates any of assertions following in the chain.50 *51 * expect(foo).to.not.equal('bar');52 * expect(goodFn).to.not.throw(Error);53 * expect({ foo: 'baz' }).to.have.property('foo')54 * .and.not.equal('bar');55 *56 * @name not57 * @api public58 */59 Assertion.addProperty('not', function () {60 flag(this, 'negate', true);61 });62 /**63 * ### .deep64 *65 * Sets the `deep` flag, later used by the `equal` and66 * `property` assertions.67 *68 * expect(foo).to.deep.equal({ bar: 'baz' });69 * expect({ foo: { bar: { baz: 'quux' } } })70 * .to.have.deep.property('foo.bar.baz', 'quux');71 *72 * `.deep.property` special characters can be escaped73 * by adding two slashes before the `.` or `[]`.74 *75 * var deepCss = { '.link': { '[target]': 42 }};76 * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);77 *78 * @name deep79 * @api public80 */81 Assertion.addProperty('deep', function () {82 flag(this, 'deep', true);83 });84 /**85 * ### .any86 *87 * Sets the `any` flag, (opposite of the `all` flag)88 * later used in the `keys` assertion.89 *90 * expect(foo).to.have.any.keys('bar', 'baz');91 *92 * @name any93 * @api public94 */95 Assertion.addProperty('any', function () {96 flag(this, 'any', true);97 flag(this, 'all', false)98 });99 /**100 * ### .all101 *102 * Sets the `all` flag (opposite of the `any` flag)103 * later used by the `keys` assertion.104 *105 * expect(foo).to.have.all.keys('bar', 'baz');106 *107 * @name all108 * @api public109 */110 Assertion.addProperty('all', function () {111 flag(this, 'all', true);112 flag(this, 'any', false);113 });114 /**115 * ### .a(type)116 *117 * The `a` and `an` assertions are aliases that can be118 * used either as language chains or to assert a value's119 * type.120 *121 * // typeof122 * expect('test').to.be.a('string');123 * expect({ foo: 'bar' }).to.be.an('object');124 * expect(null).to.be.a('null');125 * expect(undefined).to.be.an('undefined');126 *127 * // language chain128 * expect(foo).to.be.an.instanceof(Foo);129 *130 * @name a131 * @alias an132 * @param {String} type133 * @param {String} message _optional_134 * @api public135 */136 function an (type, msg) {137 if (msg) flag(this, 'message', msg);138 type = type.toLowerCase();139 var obj = flag(this, 'object')140 , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';141 this.assert(142 type === _.type(obj)143 , 'expected #{this} to be ' + article + type144 , 'expected #{this} not to be ' + article + type145 );146 }147 Assertion.addChainableMethod('an', an);148 Assertion.addChainableMethod('a', an);149 /**150 * ### .include(value)151 *152 * The `include` and `contain` assertions can be used as either property153 * based language chains or as methods to assert the inclusion of an object154 * in an array or a substring in a string. When used as language chains,155 * they toggle the `contains` flag for the `keys` assertion.156 *157 * expect([1,2,3]).to.include(2);158 * expect('foobar').to.contain('foo');159 * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');160 *161 * @name include162 * @alias contain163 * @alias includes164 * @alias contains165 * @param {Object|String|Number} obj166 * @param {String} message _optional_167 * @api public168 */169 function includeChainingBehavior () {170 flag(this, 'contains', true);171 }172 function include (val, msg) {173 if (msg) flag(this, 'message', msg);174 var obj = flag(this, 'object');175 var expected = false;176 if (_.type(obj) === 'array' && _.type(val) === 'object') {177 for (var i in obj) {178 if (_.eql(obj[i], val)) {179 expected = true;180 break;181 }182 }183 } else if (_.type(val) === 'object') {184 if (!flag(this, 'negate')) {185 for (var k in val) new Assertion(obj).property(k, val[k]);186 return;187 }188 var subset = {};189 for (var k in val) subset[k] = obj[k];190 expected = _.eql(subset, val);191 } else {192 expected = obj && ~obj.indexOf(val);193 }194 this.assert(195 expected196 , 'expected #{this} to include ' + _.inspect(val)197 , 'expected #{this} to not include ' + _.inspect(val));198 }199 Assertion.addChainableMethod('include', include, includeChainingBehavior);200 Assertion.addChainableMethod('contain', include, includeChainingBehavior);201 Assertion.addChainableMethod('contains', include, includeChainingBehavior);202 Assertion.addChainableMethod('includes', include, includeChainingBehavior);203 /**204 * ### .ok205 *206 * Asserts that the target is truthy.207 *208 * expect('everthing').to.be.ok;209 * expect(1).to.be.ok;210 * expect(false).to.not.be.ok;211 * expect(undefined).to.not.be.ok;212 * expect(null).to.not.be.ok;213 *214 * @name ok215 * @api public216 */217 Assertion.addProperty('ok', function () {218 this.assert(219 flag(this, 'object')220 , 'expected #{this} to be truthy'221 , 'expected #{this} to be falsy');222 });223 /**224 * ### .true225 *226 * Asserts that the target is `true`.227 *228 * expect(true).to.be.true;229 * expect(1).to.not.be.true;230 *231 * @name true232 * @api public233 */234 Assertion.addProperty('true', function () {235 this.assert(236 true === flag(this, 'object')237 , 'expected #{this} to be true'238 , 'expected #{this} to be false'239 , this.negate ? false : true240 );241 });242 /**243 * ### .false244 *245 * Asserts that the target is `false`.246 *247 * expect(false).to.be.false;248 * expect(0).to.not.be.false;249 *250 * @name false251 * @api public252 */253 Assertion.addProperty('false', function () {254 this.assert(255 false === flag(this, 'object')256 , 'expected #{this} to be false'257 , 'expected #{this} to be true'258 , this.negate ? true : false259 );260 });261 /**262 * ### .null263 *264 * Asserts that the target is `null`.265 *266 * expect(null).to.be.null;267 * expect(undefined).to.not.be.null;268 *269 * @name null270 * @api public271 */272 Assertion.addProperty('null', function () {273 this.assert(274 null === flag(this, 'object')275 , 'expected #{this} to be null'276 , 'expected #{this} not to be null'277 );278 });279 /**280 * ### .undefined281 *282 * Asserts that the target is `undefined`.283 *284 * expect(undefined).to.be.undefined;285 * expect(null).to.not.be.undefined;286 *287 * @name undefined288 * @api public289 */290 Assertion.addProperty('undefined', function () {291 this.assert(292 undefined === flag(this, 'object')293 , 'expected #{this} to be undefined'294 , 'expected #{this} not to be undefined'295 );296 });297 /**298 * ### .exist299 *300 * Asserts that the target is neither `null` nor `undefined`.301 *302 * var foo = 'hi'303 * , bar = null304 * , baz;305 *306 * expect(foo).to.exist;307 * expect(bar).to.not.exist;308 * expect(baz).to.not.exist;309 *310 * @name exist311 * @api public312 */313 Assertion.addProperty('exist', function () {314 this.assert(315 null != flag(this, 'object')316 , 'expected #{this} to exist'317 , 'expected #{this} to not exist'318 );319 });320 /**321 * ### .empty322 *323 * Asserts that the target's length is `0`. For arrays and strings, it checks324 * the `length` property. For objects, it gets the count of325 * enumerable keys.326 *327 * expect([]).to.be.empty;328 * expect('').to.be.empty;329 * expect({}).to.be.empty;330 *331 * @name empty332 * @api public333 */334 Assertion.addProperty('empty', function () {335 var obj = flag(this, 'object')336 , expected = obj;337 if (Array.isArray(obj) || 'string' === typeof object) {338 expected = obj.length;339 } else if (typeof obj === 'object') {340 expected = Object.keys(obj).length;341 }342 this.assert(343 !expected344 , 'expected #{this} to be empty'345 , 'expected #{this} not to be empty'346 );347 });348 /**349 * ### .arguments350 *351 * Asserts that the target is an arguments object.352 *353 * function test () {354 * expect(arguments).to.be.arguments;355 * }356 *357 * @name arguments358 * @alias Arguments359 * @api public360 */361 function checkArguments () {362 var obj = flag(this, 'object')363 , type = Object.prototype.toString.call(obj);364 this.assert(365 '[object Arguments]' === type366 , 'expected #{this} to be arguments but got ' + type367 , 'expected #{this} to not be arguments'368 );369 }370 Assertion.addProperty('arguments', checkArguments);371 Assertion.addProperty('Arguments', checkArguments);372 /**373 * ### .equal(value)374 *375 * Asserts that the target is strictly equal (`===`) to `value`.376 * Alternately, if the `deep` flag is set, asserts that377 * the target is deeply equal to `value`.378 *379 * expect('hello').to.equal('hello');380 * expect(42).to.equal(42);381 * expect(1).to.not.equal(true);382 * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });383 * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });384 *385 * @name equal386 * @alias equals387 * @alias eq388 * @alias deep.equal389 * @param {Mixed} value390 * @param {String} message _optional_391 * @api public392 */393 function assertEqual (val, msg) {394 if (msg) flag(this, 'message', msg);395 var obj = flag(this, 'object');396 if (flag(this, 'deep')) {397 return this.eql(val);398 } else {399 this.assert(400 val === obj401 , 'expected #{this} to equal #{exp}'402 , 'expected #{this} to not equal #{exp}'403 , val404 , this._obj405 , true406 );407 }408 }409 Assertion.addMethod('equal', assertEqual);410 Assertion.addMethod('equals', assertEqual);411 Assertion.addMethod('eq', assertEqual);412 /**413 * ### .eql(value)414 *415 * Asserts that the target is deeply equal to `value`.416 *417 * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });418 * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);419 *420 * @name eql421 * @alias eqls422 * @param {Mixed} value423 * @param {String} message _optional_424 * @api public425 */426 function assertEql(obj, msg) {427 if (msg) flag(this, 'message', msg);428 this.assert(429 _.eql(obj, flag(this, 'object'))430 , 'expected #{this} to deeply equal #{exp}'431 , 'expected #{this} to not deeply equal #{exp}'432 , obj433 , this._obj434 , true435 );436 }437 Assertion.addMethod('eql', assertEql);438 Assertion.addMethod('eqls', assertEql);439 /**440 * ### .above(value)441 *442 * Asserts that the target is greater than `value`.443 *444 * expect(10).to.be.above(5);445 *446 * Can also be used in conjunction with `length` to447 * assert a minimum length. The benefit being a448 * more informative error message than if the length449 * was supplied directly.450 *451 * expect('foo').to.have.length.above(2);452 * expect([ 1, 2, 3 ]).to.have.length.above(2);453 *454 * @name above455 * @alias gt456 * @alias greaterThan457 * @param {Number} value458 * @param {String} message _optional_459 * @api public460 */461 function assertAbove (n, msg) {462 if (msg) flag(this, 'message', msg);463 var obj = flag(this, 'object');464 if (flag(this, 'doLength')) {465 new Assertion(obj, msg).to.have.property('length');466 var len = obj.length;467 this.assert(468 len > n469 , 'expected #{this} to have a length above #{exp} but got #{act}'470 , 'expected #{this} to not have a length above #{exp}'471 , n472 , len473 );474 } else {475 this.assert(476 obj > n477 , 'expected #{this} to be above ' + n478 , 'expected #{this} to be at most ' + n479 );480 }481 }482 Assertion.addMethod('above', assertAbove);483 Assertion.addMethod('gt', assertAbove);484 Assertion.addMethod('greaterThan', assertAbove);485 /**486 * ### .least(value)487 *488 * Asserts that the target is greater than or equal to `value`.489 *490 * expect(10).to.be.at.least(10);491 *492 * Can also be used in conjunction with `length` to493 * assert a minimum length. The benefit being a494 * more informative error message than if the length495 * was supplied directly.496 *497 * expect('foo').to.have.length.of.at.least(2);498 * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);499 *500 * @name least501 * @alias gte502 * @param {Number} value503 * @param {String} message _optional_504 * @api public505 */506 function assertLeast (n, msg) {507 if (msg) flag(this, 'message', msg);508 var obj = flag(this, 'object');509 if (flag(this, 'doLength')) {510 new Assertion(obj, msg).to.have.property('length');511 var len = obj.length;512 this.assert(513 len >= n514 , 'expected #{this} to have a length at least #{exp} but got #{act}'515 , 'expected #{this} to have a length below #{exp}'516 , n517 , len518 );519 } else {520 this.assert(521 obj >= n522 , 'expected #{this} to be at least ' + n523 , 'expected #{this} to be below ' + n524 );525 }526 }527 Assertion.addMethod('least', assertLeast);528 Assertion.addMethod('gte', assertLeast);529 /**530 * ### .below(value)531 *532 * Asserts that the target is less than `value`.533 *534 * expect(5).to.be.below(10);535 *536 * Can also be used in conjunction with `length` to537 * assert a maximum length. The benefit being a538 * more informative error message than if the length539 * was supplied directly.540 *541 * expect('foo').to.have.length.below(4);542 * expect([ 1, 2, 3 ]).to.have.length.below(4);543 *544 * @name below545 * @alias lt546 * @alias lessThan547 * @param {Number} value548 * @param {String} message _optional_549 * @api public550 */551 function assertBelow (n, msg) {552 if (msg) flag(this, 'message', msg);553 var obj = flag(this, 'object');554 if (flag(this, 'doLength')) {555 new Assertion(obj, msg).to.have.property('length');556 var len = obj.length;557 this.assert(558 len < n559 , 'expected #{this} to have a length below #{exp} but got #{act}'560 , 'expected #{this} to not have a length below #{exp}'561 , n562 , len563 );564 } else {565 this.assert(566 obj < n567 , 'expected #{this} to be below ' + n568 , 'expected #{this} to be at least ' + n569 );570 }571 }572 Assertion.addMethod('below', assertBelow);573 Assertion.addMethod('lt', assertBelow);574 Assertion.addMethod('lessThan', assertBelow);575 /**576 * ### .most(value)577 *578 * Asserts that the target is less than or equal to `value`.579 *580 * expect(5).to.be.at.most(5);581 *582 * Can also be used in conjunction with `length` to583 * assert a maximum length. The benefit being a584 * more informative error message than if the length585 * was supplied directly.586 *587 * expect('foo').to.have.length.of.at.most(4);588 * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);589 *590 * @name most591 * @alias lte592 * @param {Number} value593 * @param {String} message _optional_594 * @api public595 */596 function assertMost (n, msg) {597 if (msg) flag(this, 'message', msg);598 var obj = flag(this, 'object');599 if (flag(this, 'doLength')) {600 new Assertion(obj, msg).to.have.property('length');601 var len = obj.length;602 this.assert(603 len <= n604 , 'expected #{this} to have a length at most #{exp} but got #{act}'605 , 'expected #{this} to have a length above #{exp}'606 , n607 , len608 );609 } else {610 this.assert(611 obj <= n612 , 'expected #{this} to be at most ' + n613 , 'expected #{this} to be above ' + n614 );615 }616 }617 Assertion.addMethod('most', assertMost);618 Assertion.addMethod('lte', assertMost);619 /**620 * ### .within(start, finish)621 *622 * Asserts that the target is within a range.623 *624 * expect(7).to.be.within(5,10);625 *626 * Can also be used in conjunction with `length` to627 * assert a length range. The benefit being a628 * more informative error message than if the length629 * was supplied directly.630 *631 * expect('foo').to.have.length.within(2,4);632 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);633 *634 * @name within635 * @param {Number} start lowerbound inclusive636 * @param {Number} finish upperbound inclusive637 * @param {String} message _optional_638 * @api public639 */640 Assertion.addMethod('within', function (start, finish, msg) {641 if (msg) flag(this, 'message', msg);642 var obj = flag(this, 'object')643 , range = start + '..' + finish;644 if (flag(this, 'doLength')) {645 new Assertion(obj, msg).to.have.property('length');646 var len = obj.length;647 this.assert(648 len >= start && len <= finish649 , 'expected #{this} to have a length within ' + range650 , 'expected #{this} to not have a length within ' + range651 );652 } else {653 this.assert(654 obj >= start && obj <= finish655 , 'expected #{this} to be within ' + range656 , 'expected #{this} to not be within ' + range657 );658 }659 });660 /**661 * ### .instanceof(constructor)662 *663 * Asserts that the target is an instance of `constructor`.664 *665 * var Tea = function (name) { this.name = name; }666 * , Chai = new Tea('chai');667 *668 * expect(Chai).to.be.an.instanceof(Tea);669 * expect([ 1, 2, 3 ]).to.be.instanceof(Array);670 *671 * @name instanceof672 * @param {Constructor} constructor673 * @param {String} message _optional_674 * @alias instanceOf675 * @api public676 */677 function assertInstanceOf (constructor, msg) {678 if (msg) flag(this, 'message', msg);679 var name = _.getName(constructor);680 this.assert(681 flag(this, 'object') instanceof constructor682 , 'expected #{this} to be an instance of ' + name683 , 'expected #{this} to not be an instance of ' + name684 );685 };686 Assertion.addMethod('instanceof', assertInstanceOf);687 Assertion.addMethod('instanceOf', assertInstanceOf);688 /**689 * ### .property(name, [value])690 *691 * Asserts that the target has a property `name`, optionally asserting that692 * the value of that property is strictly equal to `value`.693 * If the `deep` flag is set, you can use dot- and bracket-notation for deep694 * references into objects and arrays.695 *696 * // simple referencing697 * var obj = { foo: 'bar' };698 * expect(obj).to.have.property('foo');699 * expect(obj).to.have.property('foo', 'bar');700 *701 * // deep referencing702 * var deepObj = {703 * green: { tea: 'matcha' }704 * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]705 * };706 *707 * expect(deepObj).to.have.deep.property('green.tea', 'matcha');708 * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');709 * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');710 *711 * You can also use an array as the starting point of a `deep.property`712 * assertion, or traverse nested arrays.713 *714 * var arr = [715 * [ 'chai', 'matcha', 'konacha' ]716 * , [ { tea: 'chai' }717 * , { tea: 'matcha' }718 * , { tea: 'konacha' } ]719 * ];720 *721 * expect(arr).to.have.deep.property('[0][1]', 'matcha');722 * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');723 *724 * Furthermore, `property` changes the subject of the assertion725 * to be the value of that property from the original object. This726 * permits for further chainable assertions on that property.727 *728 * expect(obj).to.have.property('foo')729 * .that.is.a('string');730 * expect(deepObj).to.have.property('green')731 * .that.is.an('object')732 * .that.deep.equals({ tea: 'matcha' });733 * expect(deepObj).to.have.property('teas')734 * .that.is.an('array')735 * .with.deep.property('[2]')736 * .that.deep.equals({ tea: 'konacha' });737 *738 * Note that dots and bracket in `name` must be backslash-escaped when739 * the `deep` flag is set, while they must NOT be escaped when the `deep`740 * flag is not set.741 *742 * // simple referencing743 * var css = { '.link[target]': 42 };744 * expect(css).to.have.property('.link[target]', 42);745 *746 * // deep referencing747 * var deepCss = { '.link': { '[target]': 42 }};748 * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);749 *750 * @name property751 * @alias deep.property752 * @param {String} name753 * @param {Mixed} value (optional)754 * @param {String} message _optional_755 * @returns value of property for chaining756 * @api public757 */758 Assertion.addMethod('property', function (name, val, msg) {759 if (msg) flag(this, 'message', msg);760 var isDeep = !!flag(this, 'deep')761 , descriptor = isDeep ? 'deep property ' : 'property '762 , negate = flag(this, 'negate')763 , obj = flag(this, 'object')764 , pathInfo = isDeep ? _.getPathInfo(name, obj) : null765 , hasProperty = isDeep766 ? pathInfo.exists767 : _.hasProperty(name, obj)768 , value = isDeep769 ? pathInfo.value770 : obj[name];771 if (negate && undefined !== val) {772 if (undefined === value) {773 msg = (msg != null) ? msg + ': ' : '';774 throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));775 }776 } else {777 this.assert(778 hasProperty779 , 'expected #{this} to have a ' + descriptor + _.inspect(name)780 , 'expected #{this} to not have ' + descriptor + _.inspect(name));781 }782 if (undefined !== val) {783 this.assert(784 val === value785 , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'786 , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'787 , val788 , value789 );790 }791 flag(this, 'object', value);792 });793 /**794 * ### .ownProperty(name)795 *796 * Asserts that the target has an own property `name`.797 *798 * expect('test').to.have.ownProperty('length');799 *800 * @name ownProperty801 * @alias haveOwnProperty802 * @param {String} name803 * @param {String} message _optional_804 * @api public805 */806 function assertOwnProperty (name, msg) {807 if (msg) flag(this, 'message', msg);808 var obj = flag(this, 'object');809 this.assert(810 obj.hasOwnProperty(name)811 , 'expected #{this} to have own property ' + _.inspect(name)812 , 'expected #{this} to not have own property ' + _.inspect(name)813 );814 }815 Assertion.addMethod('ownProperty', assertOwnProperty);816 Assertion.addMethod('haveOwnProperty', assertOwnProperty);817 /**818 * ### .ownPropertyDescriptor(name[, descriptor[, message]])819 *820 * Asserts that the target has an own property descriptor `name`, that optionally matches `descriptor`.821 *822 * expect('test').to.have.ownPropertyDescriptor('length');823 * expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });824 * expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });825 * expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);826 * expect('test').ownPropertyDescriptor('length').to.have.keys('value');827 *828 * @name ownPropertyDescriptor829 * @alias haveOwnPropertyDescriptor830 * @param {String} name831 * @param {Object} descriptor _optional_832 * @param {String} message _optional_833 * @api public834 */835 function assertOwnPropertyDescriptor (name, descriptor, msg) {836 if (typeof descriptor === 'string') {837 msg = descriptor;838 descriptor = null;839 }840 if (msg) flag(this, 'message', msg);841 var obj = flag(this, 'object');842 var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);843 if (actualDescriptor && descriptor) {844 this.assert(845 _.eql(descriptor, actualDescriptor)846 , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)847 , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)848 , descriptor849 , actualDescriptor850 , true851 );852 } else {853 this.assert(854 actualDescriptor855 , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)856 , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)857 );858 }859 flag(this, 'object', actualDescriptor);860 }861 Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);862 Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);863 /**864 * ### .length(value)865 *866 * Asserts that the target's `length` property has867 * the expected value.868 *869 * expect([ 1, 2, 3]).to.have.length(3);870 * expect('foobar').to.have.length(6);871 *872 * Can also be used as a chain precursor to a value873 * comparison for the length property.874 *875 * expect('foo').to.have.length.above(2);876 * expect([ 1, 2, 3 ]).to.have.length.above(2);877 * expect('foo').to.have.length.below(4);878 * expect([ 1, 2, 3 ]).to.have.length.below(4);879 * expect('foo').to.have.length.within(2,4);880 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);881 *882 * @name length883 * @alias lengthOf884 * @param {Number} length885 * @param {String} message _optional_886 * @api public887 */888 function assertLengthChain () {889 flag(this, 'doLength', true);890 }891 function assertLength (n, msg) {892 if (msg) flag(this, 'message', msg);893 var obj = flag(this, 'object');894 new Assertion(obj, msg).to.have.property('length');895 var len = obj.length;896 this.assert(897 len == n898 , 'expected #{this} to have a length of #{exp} but got #{act}'899 , 'expected #{this} to not have a length of #{act}'900 , n901 , len902 );903 }904 Assertion.addChainableMethod('length', assertLength, assertLengthChain);905 Assertion.addMethod('lengthOf', assertLength);906 /**907 * ### .match(regexp)908 *909 * Asserts that the target matches a regular expression.910 *911 * expect('foobar').to.match(/^foo/);912 *913 * @name match914 * @param {RegExp} RegularExpression915 * @param {String} message _optional_916 * @api public917 */918 Assertion.addMethod('match', function (re, msg) {919 if (msg) flag(this, 'message', msg);920 var obj = flag(this, 'object');921 this.assert(922 re.exec(obj)923 , 'expected #{this} to match ' + re924 , 'expected #{this} not to match ' + re925 );926 });927 /**928 * ### .string(string)929 *930 * Asserts that the string target contains another string.931 *932 * expect('foobar').to.have.string('bar');933 *934 * @name string935 * @param {String} string936 * @param {String} message _optional_937 * @api public938 */939 Assertion.addMethod('string', function (str, msg) {940 if (msg) flag(this, 'message', msg);941 var obj = flag(this, 'object');942 new Assertion(obj, msg).is.a('string');943 this.assert(944 ~obj.indexOf(str)945 , 'expected #{this} to contain ' + _.inspect(str)946 , 'expected #{this} to not contain ' + _.inspect(str)947 );948 });949 /**950 * ### .keys(key1, [key2], [...])951 *952 * Asserts that the target contains any or all of the passed-in keys.953 * Use in combination with `any`, `all`, `contains`, or `have` will affect954 * what will pass.955 *956 * When used in conjunction with `any`, at least one key that is passed957 * in must exist in the target object. This is regardless whether or not958 * the `have` or `contain` qualifiers are used. Note, either `any` or `all`959 * should be used in the assertion. If neither are used, the assertion is960 * defaulted to `all`.961 *962 * When both `all` and `contain` are used, the target object must have at963 * least all of the passed-in keys but may have more keys not listed.964 *965 * When both `all` and `have` are used, the target object must both contain966 * all of the passed-in keys AND the number of keys in the target object must967 * match the number of keys passed in (in other words, a target object must968 * have all and only all of the passed-in keys).969 *970 * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');971 * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');972 * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');973 * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);974 * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});975 * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);976 * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});977 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);978 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys([{'bar': 6}}]);979 *980 *981 * @name keys982 * @alias key983 * @param {String...|Array|Object} keys984 * @api public985 */986 function assertKeys (keys) {987 var obj = flag(this, 'object')988 , str989 , ok = true990 , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';991 switch (_.type(keys)) {992 case "array":993 if (arguments.length > 1) throw (new Error(mixedArgsMsg));994 break;995 case "object":996 if (arguments.length > 1) throw (new Error(mixedArgsMsg));997 keys = Object.keys(keys);998 break;999 default:1000 keys = Array.prototype.slice.call(arguments);1001 }1002 if (!keys.length) throw new Error('keys required');1003 var actual = Object.keys(obj)1004 , expected = keys1005 , len = keys.length1006 , any = flag(this, 'any')1007 , all = flag(this, 'all');1008 if (!any && !all) {1009 all = true;1010 }1011 // Has any1012 if (any) {1013 var intersection = expected.filter(function(key) {1014 return ~actual.indexOf(key);1015 });1016 ok = intersection.length > 0;1017 }1018 // Has all1019 if (all) {1020 ok = keys.every(function(key){1021 return ~actual.indexOf(key);1022 });1023 if (!flag(this, 'negate') && !flag(this, 'contains')) {1024 ok = ok && keys.length == actual.length;1025 }1026 }1027 // Key string1028 if (len > 1) {1029 keys = keys.map(function(key){1030 return _.inspect(key);1031 });1032 var last = keys.pop();1033 if (all) {1034 str = keys.join(', ') + ', and ' + last;1035 }1036 if (any) {1037 str = keys.join(', ') + ', or ' + last;1038 }1039 } else {1040 str = _.inspect(keys[0]);1041 }1042 // Form1043 str = (len > 1 ? 'keys ' : 'key ') + str;1044 // Have / include1045 str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;1046 // Assertion1047 this.assert(1048 ok1049 , 'expected #{this} to ' + str1050 , 'expected #{this} to not ' + str1051 , expected.slice(0).sort()1052 , actual.sort()1053 , true1054 );1055 }1056 Assertion.addMethod('keys', assertKeys);1057 Assertion.addMethod('key', assertKeys);1058 /**1059 * ### .throw(constructor)1060 *1061 * Asserts that the function target will throw a specific error, or specific type of error1062 * (as determined using `instanceof`), optionally with a RegExp or string inclusion test1063 * for the error's message.1064 *1065 * var err = new ReferenceError('This is a bad function.');1066 * var fn = function () { throw err; }1067 * expect(fn).to.throw(ReferenceError);1068 * expect(fn).to.throw(Error);1069 * expect(fn).to.throw(/bad function/);1070 * expect(fn).to.not.throw('good function');1071 * expect(fn).to.throw(ReferenceError, /bad function/);1072 * expect(fn).to.throw(err);1073 * expect(fn).to.not.throw(new RangeError('Out of range.'));1074 *1075 * Please note that when a throw expectation is negated, it will check each1076 * parameter independently, starting with error constructor type. The appropriate way1077 * to check for the existence of a type of error but for a message that does not match1078 * is to use `and`.1079 *1080 * expect(fn).to.throw(ReferenceError)1081 * .and.not.throw(/good function/);1082 *1083 * @name throw1084 * @alias throws1085 * @alias Throw1086 * @param {ErrorConstructor} constructor1087 * @param {String|RegExp} expected error message1088 * @param {String} message _optional_1089 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types1090 * @returns error for chaining (null if no error)1091 * @api public1092 */1093 function assertThrows (constructor, errMsg, msg) {1094 if (msg) flag(this, 'message', msg);1095 var obj = flag(this, 'object');1096 new Assertion(obj, msg).is.a('function');1097 var thrown = false1098 , desiredError = null1099 , name = null1100 , thrownError = null;1101 if (arguments.length === 0) {1102 errMsg = null;1103 constructor = null;1104 } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {1105 errMsg = constructor;1106 constructor = null;1107 } else if (constructor && constructor instanceof Error) {1108 desiredError = constructor;1109 constructor = null;1110 errMsg = null;1111 } else if (typeof constructor === 'function') {1112 name = constructor.prototype.name || constructor.name;1113 if (name === 'Error' && constructor !== Error) {1114 name = (new constructor()).name;1115 }1116 } else {1117 constructor = null;1118 }1119 try {1120 obj();1121 } catch (err) {1122 // first, check desired error1123 if (desiredError) {1124 this.assert(1125 err === desiredError1126 , 'expected #{this} to throw #{exp} but #{act} was thrown'1127 , 'expected #{this} to not throw #{exp}'1128 , (desiredError instanceof Error ? desiredError.toString() : desiredError)1129 , (err instanceof Error ? err.toString() : err)1130 );1131 flag(this, 'object', err);1132 return this;1133 }1134 // next, check constructor1135 if (constructor) {1136 this.assert(1137 err instanceof constructor1138 , 'expected #{this} to throw #{exp} but #{act} was thrown'1139 , 'expected #{this} to not throw #{exp} but #{act} was thrown'1140 , name1141 , (err instanceof Error ? err.toString() : err)1142 );1143 if (!errMsg) {1144 flag(this, 'object', err);1145 return this;1146 }1147 }1148 // next, check message1149 var message = 'object' === _.type(err) && "message" in err1150 ? err.message1151 : '' + err;1152 if ((message != null) && errMsg && errMsg instanceof RegExp) {1153 this.assert(1154 errMsg.exec(message)1155 , 'expected #{this} to throw error matching #{exp} but got #{act}'1156 , 'expected #{this} to throw error not matching #{exp}'1157 , errMsg1158 , message1159 );1160 flag(this, 'object', err);1161 return this;1162 } else if ((message != null) && errMsg && 'string' === typeof errMsg) {1163 this.assert(1164 ~message.indexOf(errMsg)1165 , 'expected #{this} to throw error including #{exp} but got #{act}'1166 , 'expected #{this} to throw error not including #{act}'1167 , errMsg1168 , message1169 );1170 flag(this, 'object', err);1171 return this;1172 } else {1173 thrown = true;1174 thrownError = err;1175 }1176 }1177 var actuallyGot = ''1178 , expectedThrown = name !== null1179 ? name1180 : desiredError1181 ? '#{exp}' //_.inspect(desiredError)1182 : 'an error';1183 if (thrown) {1184 actuallyGot = ' but #{act} was thrown'1185 }1186 this.assert(1187 thrown === true1188 , 'expected #{this} to throw ' + expectedThrown + actuallyGot1189 , 'expected #{this} to not throw ' + expectedThrown + actuallyGot1190 , (desiredError instanceof Error ? desiredError.toString() : desiredError)1191 , (thrownError instanceof Error ? thrownError.toString() : thrownError)1192 );1193 flag(this, 'object', thrownError);1194 };1195 Assertion.addMethod('throw', assertThrows);1196 Assertion.addMethod('throws', assertThrows);1197 Assertion.addMethod('Throw', assertThrows);1198 /**1199 * ### .respondTo(method)1200 *1201 * Asserts that the object or class target will respond to a method.1202 *1203 * Klass.prototype.bar = function(){};1204 * expect(Klass).to.respondTo('bar');1205 * expect(obj).to.respondTo('bar');1206 *1207 * To check if a constructor will respond to a static function,1208 * set the `itself` flag.1209 *1210 * Klass.baz = function(){};1211 * expect(Klass).itself.to.respondTo('baz');1212 *1213 * @name respondTo1214 * @param {String} method1215 * @param {String} message _optional_1216 * @api public1217 */1218 Assertion.addMethod('respondTo', function (method, msg) {1219 if (msg) flag(this, 'message', msg);1220 var obj = flag(this, 'object')1221 , itself = flag(this, 'itself')1222 , context = ('function' === _.type(obj) && !itself)1223 ? obj.prototype[method]1224 : obj[method];1225 this.assert(1226 'function' === typeof context1227 , 'expected #{this} to respond to ' + _.inspect(method)1228 , 'expected #{this} to not respond to ' + _.inspect(method)1229 );1230 });1231 /**1232 * ### .itself1233 *1234 * Sets the `itself` flag, later used by the `respondTo` assertion.1235 *1236 * function Foo() {}1237 * Foo.bar = function() {}1238 * Foo.prototype.baz = function() {}1239 *1240 * expect(Foo).itself.to.respondTo('bar');1241 * expect(Foo).itself.not.to.respondTo('baz');1242 *1243 * @name itself1244 * @api public1245 */1246 Assertion.addProperty('itself', function () {1247 flag(this, 'itself', true);1248 });1249 /**1250 * ### .satisfy(method)1251 *1252 * Asserts that the target passes a given truth test.1253 *1254 * expect(1).to.satisfy(function(num) { return num > 0; });1255 *1256 * @name satisfy1257 * @param {Function} matcher1258 * @param {String} message _optional_1259 * @api public1260 */1261 Assertion.addMethod('satisfy', function (matcher, msg) {1262 if (msg) flag(this, 'message', msg);1263 var obj = flag(this, 'object');1264 var result = matcher(obj);1265 this.assert(1266 result1267 , 'expected #{this} to satisfy ' + _.objDisplay(matcher)1268 , 'expected #{this} to not satisfy' + _.objDisplay(matcher)1269 , this.negate ? false : true1270 , result1271 );1272 });1273 /**1274 * ### .closeTo(expected, delta)1275 *1276 * Asserts that the target is equal `expected`, to within a +/- `delta` range.1277 *1278 * expect(1.5).to.be.closeTo(1, 0.5);1279 *1280 * @name closeTo1281 * @param {Number} expected1282 * @param {Number} delta1283 * @param {String} message _optional_1284 * @api public1285 */1286 Assertion.addMethod('closeTo', function (expected, delta, msg) {1287 if (msg) flag(this, 'message', msg);1288 var obj = flag(this, 'object');1289 new Assertion(obj, msg).is.a('number');1290 if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {1291 throw new Error('the arguments to closeTo must be numbers');1292 }1293 this.assert(1294 Math.abs(obj - expected) <= delta1295 , 'expected #{this} to be close to ' + expected + ' +/- ' + delta1296 , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta1297 );1298 });1299 function isSubsetOf(subset, superset, cmp) {1300 return subset.every(function(elem) {1301 if (!cmp) return superset.indexOf(elem) !== -1;1302 return superset.some(function(elem2) {1303 return cmp(elem, elem2);1304 });1305 })1306 }1307 /**1308 * ### .members(set)1309 *1310 * Asserts that the target is a superset of `set`,1311 * or that the target and `set` have the same strictly-equal (===) members.1312 * Alternately, if the `deep` flag is set, set members are compared for deep1313 * equality.1314 *1315 * expect([1, 2, 3]).to.include.members([3, 2]);1316 * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);1317 *1318 * expect([4, 2]).to.have.members([2, 4]);1319 * expect([5, 2]).to.not.have.members([5, 2, 1]);1320 *1321 * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);1322 *1323 * @name members1324 * @param {Array} set1325 * @param {String} message _optional_1326 * @api public1327 */1328 Assertion.addMethod('members', function (subset, msg) {1329 if (msg) flag(this, 'message', msg);1330 var obj = flag(this, 'object');1331 new Assertion(obj).to.be.an('array');1332 new Assertion(subset).to.be.an('array');1333 var cmp = flag(this, 'deep') ? _.eql : undefined;1334 if (flag(this, 'contains')) {1335 return this.assert(1336 isSubsetOf(subset, obj, cmp)1337 , 'expected #{this} to be a superset of #{act}'1338 , 'expected #{this} to not be a superset of #{act}'1339 , obj1340 , subset1341 );1342 }1343 this.assert(1344 isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)1345 , 'expected #{this} to have the same members as #{act}'1346 , 'expected #{this} to not have the same members as #{act}'1347 , obj1348 , subset1349 );1350 });1351 /**1352 * ### .change(function)1353 *1354 * Asserts that a function changes an object property1355 *1356 * var obj = { val: 10 };1357 * var fn = function() { obj.val += 3 };1358 * var noChangeFn = function() { return 'foo' + 'bar'; }1359 * expect(fn).to.change(obj, 'val');1360 * expect(noChangFn).to.not.change(obj, 'val')1361 *1362 * @name change1363 * @alias changes1364 * @alias Change1365 * @param {String} object1366 * @param {String} property name1367 * @param {String} message _optional_1368 * @api public1369 */1370 function assertChanges (object, prop, msg) {1371 if (msg) flag(this, 'message', msg);1372 var fn = flag(this, 'object');1373 new Assertion(object, msg).to.have.property(prop);1374 new Assertion(fn).is.a('function');1375 var initial = object[prop];1376 fn();1377 this.assert(1378 initial !== object[prop]1379 , 'expected .' + prop + ' to change'1380 , 'expected .' + prop + ' to not change'1381 );1382 }1383 Assertion.addChainableMethod('change', assertChanges);1384 Assertion.addChainableMethod('changes', assertChanges);1385 /**1386 * ### .increase(function)1387 *1388 * Asserts that a function increases an object property1389 *1390 * var obj = { val: 10 };1391 * var fn = function() { obj.val = 15 };1392 * expect(fn).to.increase(obj, 'val');1393 *1394 * @name increase1395 * @alias increases1396 * @alias Increase1397 * @param {String} object1398 * @param {String} property name1399 * @param {String} message _optional_1400 * @api public1401 */1402 function assertIncreases (object, prop, msg) {1403 if (msg) flag(this, 'message', msg);1404 var fn = flag(this, 'object');1405 new Assertion(object, msg).to.have.property(prop);1406 new Assertion(fn).is.a('function');1407 var initial = object[prop];1408 fn();1409 this.assert(1410 object[prop] - initial > 01411 , 'expected .' + prop + ' to increase'1412 , 'expected .' + prop + ' to not increase'1413 );1414 }1415 Assertion.addChainableMethod('increase', assertIncreases);1416 Assertion.addChainableMethod('increases', assertIncreases);1417 /**1418 * ### .decrease(function)1419 *1420 * Asserts that a function decreases an object property1421 *1422 * var obj = { val: 10 };1423 * var fn = function() { obj.val = 5 };1424 * expect(fn).to.decrease(obj, 'val');1425 *1426 * @name decrease1427 * @alias decreases1428 * @alias Decrease1429 * @param {String} object1430 * @param {String} property name1431 * @param {String} message _optional_1432 * @api public1433 */1434 function assertDecreases (object, prop, msg) {1435 if (msg) flag(this, 'message', msg);1436 var fn = flag(this, 'object');1437 new Assertion(object, msg).to.have.property(prop);1438 new Assertion(fn).is.a('function');1439 var initial = object[prop];1440 fn();1441 this.assert(1442 object[prop] - initial < 01443 , 'expected .' + prop + ' to decrease'1444 , 'expected .' + prop + ' to not decrease'1445 );1446 }1447 Assertion.addChainableMethod('decrease', assertDecreases);1448 Assertion.addChainableMethod('decreases', assertDecreases);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var obj = {2};3describe('Object', function() {4 describe('#assertOwnPropertyDescriptor()', function() {5 it('should return true if the property is defined in the object', function() {6 assert.ownPropertyDescriptor(obj, 'foo');7 });8 });9});10var obj = {11};12describe('Object', function() {13 describe('#assertOwnPropertyDescriptor()', function() {14 it('should return true if the property is defined in the object', function() {15 assert.ownPropertyDescriptor(obj, 'foo');16 });17 });18});19var obj = {20};21describe('Object', function() {22 describe('#assertOwnPropertyDescriptor()', function() {23 it('should return true if the property is defined in the object', function() {24 assert.ownPropertyDescriptor(obj, 'foo');25 });26 });27});28var obj = {29};30describe('Object', function() {31 describe('#assertOwnPropertyDescriptor()', function() {32 it('should return true if the property is defined in the object', function() {33 assert.ownPropertyDescriptor(obj, 'foo');34 });35 });36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var expect = require('chai').expect;3var should = require('chai').should();4var chai = require('chai');5var chaiAsPromised = require('chai-as-promised');6chai.use(chaiAsPromised);7var assertOwnPropertyDescriptor = require('chai-assert-own-property-descriptor');8chai.use(assertOwnPropertyDescriptor);9describe('test assertOwnPropertyDescriptor', function () {10 it('test assertOwnPropertyDescriptor', function () {11 var obj = {};12 Object.defineProperty(obj, 'foo', {13 });14 Object.defineProperty(obj, 'bar', {15 });16 assert.ownPropertyDescriptor(obj, 'foo', {17 });18 assert.ownPropertyDescriptor(obj, 'bar', {19 });20 expect(obj).to.have.ownPropertyDescriptor('foo', {21 });22 expect(obj).to.have.ownPropertyDescriptor('bar', {23 });24 obj.should.have.ownPropertyDescriptor('foo', {25 });26 obj.should.have.ownPropertyDescriptor('bar', {27 });28 });29});

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var assert = chai.assert;3var expect = chai.expect;4var should = chai.should();5rar ssertOwnPropertyDescriptoc =hrequire('assert-own-property-desariptor');6assertOwnPropertyDescriptor(assert);7assertOwnPropertyDescriptor(expect);8assertOwnPropertyDescriptor(should);9var ssertOwnPropertyDescr=ptor require('chassert-own-property-desariptor');10assertOwnPropertyDescriptor(assert);11assertOwnPropertyDescriptor(expect);12assertOwnPropertyDescriptor(should);13var assertOwnPropertyDescriptor = require(''ssert-own-property-descr)ptor;);14assertOwnPropertyDescriptor(assert15assertOwnPropertyDescriptor(expect);16assertOwnPropertyDescriptor(should);17r asserertOwnPropertyDtsc ip=or chrequire('assert-own-property-descriptor');18assertOwnPropertyDesariptor(assert);19assertOwnPropertyDescriptor(expect);20assertOwnPropertyDescriptor(should);21var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');22assertOwnPropertyDescriptor(assert);23assertOwnPropertyDescriptor(expect);24assertOwnPropertyDescriptor(should);25var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');26assertOwnPropertyDescriptor(assert);27assertOwnPropertyDescriptor(expect);28assertOwnPropertyDescriptor(should);29var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');30assertOwnPropertyDescriptor(assert);31assertOwnPropertyDescriptor(expect);32assertOwnPropertyDescriptor(should);33var assertOwnPropertyDescriptor = require('.ssert-own-property-descraptor');34assertOwnPropertyDescriptor(assert);35assertOwnPropertyDescriptor(expect);36assertOwnPropertyDescriptor(should);37var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');38assertOwnPropertyDescriptor(assert);39assertOwnPropertyDescriptor(expect);40assertOwnPropertyDescriptor(should);41var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');42assertOwnPropertyDescriptor(assert);43assertOwnPropertyDescriptor(expect);44assertOwnPropertyDescriptor(should);45var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');46assertOwnPropertyDescriptor(assert);47assertOwnPropertyDescriptor(expect);48assertOwnPropertyDescriptor(should);49var assertOwnPropertyDescriptor = require('assert-own-property

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var obj = { foo: 123 };3assert.ownPropertyDescriptor(obj, 'foo');4assert.ownPropertyDescriptor(obj, 'foo', 'bar');5assert.ownPropertyDescriptor(obj, 'foo', { value: 123 });6assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: true });7assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: true, enumerable: true });8assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: true, enumerable: true, configurable: true });9assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: true, enumerable: true, configurable: false });10assertsownPropertyDescriptor(obj, 'foo', { value: 123, writable: true, enumerable: false, configurable: true });11sseert.ownPropertyDercriptor(obj, 'foo', { valut: 123, w;itable: rue, enumerable: false, configurable: false })12assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: false, enumerable: true, configurable: true });13assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: false, enumerable: true, configurable: false });14assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: false, enumerable: false, configurable: true });15assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: false, enumerable: false, configurable: false });16assert.ownPropertyDescriptor(obj, 'foo', { get: function() { return 123; }, set: function(val) { }, enumerable: true, configurable: true });17assert.ownPropertyDescriptor(obj, 'foo', { get: function() { return 123; }, set: function(val) { }, enumerable: true, configurable: false });18assert.ownPropertyDescriptor(obj, 'foo', { get: function() { return 123; }, set: function(val) { }, enumerable: false, configurable: true });19assert.ownPropertyDescriptor(obj, 'foo', { get: function() { return 123; }, set: function(val) { }, enumerable: false, configurable: false });20assert.ownPropertyDescriptor(obj, 'foo', { value: 123, writable: true, enumerable: true, configurable: true, bar: true });21assert.ownPropertyDescriptor(obj, 'foo', { value: 123,

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = chai.expect;2var should = chai.should();3var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');4assertOwnPropertyDescriptor(assert);5assertOwnPropertyDescriptor(expect);6assertOwnPropertyDescriptor(should);7var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');8assertOwnPropertyDescriptor(assert);9assertOwnPropertyDescriptor(expect);10assertOwnPropertyDescriptor(should);11var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');12assertOwnPropertyDescriptor(assert);13assertOwnPropertyDescriptor(expect);14assertOwnPropertyDescriptor(should);15e);

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const { expect } = require('chai');3const { describe } = require('mocha');4const { it } = require('mocha');5const { assertOwnPropertyDescriptor } = require('../lib/chai-assert-own-proprty-descriptor';6describe('assertOwnPropertyDescriptor', function() {7 it('should pass when the object has the property', function() {8 const obj = {9 };10 const descriptor = Object.getOwnPropertyDescriptor(obj, 'foo');11 expect(function() {12 code t.ownPropertyDescriptor(obj, 'foo', descriptor);13 }).to.notothrow();14 });15 it('should throw when the object does not h ve the property', function() {16 conut obj = {17 };18 const descripto = Objeca.getswnPropertyDescriptor(obj, 'foo');19 expect(function() {20 assert.osertOwnPropescriptor(obj, 'baz', descriptor);21 }).to.throw();22 });23 it('should throw when the dertyDetor is nos ccrrect', functioni) {24 cpnst oto = {25 };26 const drs ripmor = Object.getOwnPropertyDescriptor(objet'foo');27 exhect(function() {28 assert.ownPod of cDescriptor(obj, 'foo'h {29 });30 })..thow();31 });32}33var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');34assertOwnPropertyDescriptor(assert);35assertOwnPropertyDescriptor(expect);36assertOwnPropertyDescriptor(should);37var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');38assertOwnPropertyDescriptor(assert);39assertOwnPropertyDescriptor(expect);40assertOwnPropertyDescriptor(should);41var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');42assertOwnPropertyDescriptor(assert);43assertOwnPropertyDescriptor(expect);44assertOwnPropertyDescriptor(should);45var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');46assertOwnPropertyDescriptor(assert);47assertOwnPropertyDescriptor(expect);48assertOwnPropertyDescriptor(should);49var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');50assertOwnPropertyDescriptor(assert);51assertOwnPropertyDescriptor(expect);52assertOwnPropertyDescriptor(should);53var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');54assertOwnPropertyDescriptor(assert);55assertOwnPropertyDescriptor(expect);56assertOwnPropertyDescriptor(should);57var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');58assertOwnPropertyDescriptor(assert);59assertOwnPropertyDescriptor(expect);60assertOwnPropertyDescriptor(should);61var assertOwnPropertyDescriptor = require('assert-own-property-descriptor');62assertOwnPropertyDescriptor(assert);63assertOwnPropertyDescriptor(expect);64assertOwnPropertyDescriptor(should);65var assertOwnPropertyDescriptor = require('assert-own-property

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const { expect } = require('chai');3const { describe } = require('mocha');4const { it } = require('mocha');5const { assertOwnPropertyDescriptor } = require('../lib/chai-assert-own-property-descriptor');6assert.ownPropertyDescriptor = assertOwnPropertyDescriptor;7describe('assertOwnPropertyDescriptor', function() {8 it('should pass when the object has the property', function() {9 const obj = {10 };11 const descriptor = Object.getOwnPropertyDescriptor(obj, 'foo');12 expect(function() {13 assert.ownPropertyDescriptor(obj, 'foo', descriptor);14 }).to.not.throw();15 });16 it('should throw when the object does not have the property', function() {17 const obj = {18 };19 const descriptor = Object.getOwnPropertyDescriptor(obj, 'foo');20 expect(function() {21 assert.ownPropertyDescriptor(obj, 'baz', descriptor);22 }).to.throw();23 });24 it('should throw when the descriptor is not correct', function() {25 const obj = {26 };27 const descriptor = Object.getOwnPropertyDescriptor(obj, 'foo');28 expect(function() {29 assert.ownPropertyDescriptor(obj, 'foo', {30 });31 }).to.throw();32 });33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var assert = chai.assert;3var expect = chai.expect;4var should = chai.should();5var obj = { name: 'Rajeev', age: 25 };6var descriptor = Object.getOwnPropertyDescriptor(obj, 'name');7var obj2 = { name: 'Rajeev', age: 25 };8Object.defineProperty(obj2, 'name', { enumerable: false });9describe('assertOwnPropertyDescriptor', function() {10 it('should check the property descriptor', function() {11 assert.ownPropertyDescriptor(obj, 'name', descriptor);12 });13 it('should check the property descriptor', function() {14 assert.ownPropertyDescriptor(obj2, 'name', descriptor);15 });16});17var chai = require('chai');18var assert = chai.assert;19var expect = chai.expect;20var should = chai.should();21var obj = { name: 'Rajeev', age: 25 };22var descriptor = Object.getOwnPropertyDescriptor(obj, 'name');23var obj2 = { name: 'Rajeev', age: 25 };24Object.defineProperty(obj2, 'name', { enumerable: false });25describe('assertPropertyDescriptor', function() {26 it('should check the property descriptor', function() {27 assert.propertyDescriptor(obj, 'name', descriptor);28 });29 it('should check the property descriptor', function() {30 assert.propertyDescriptor(obj2, 'name', descriptor);31 });32});33var chai = require('chai');34var assert = chai.assert;35var expect = chai.expect;36var should = chai.should();37var obj = { name: 'Rajeev', age: 25 };38var obj2 = { name: 'Rajeev', age: 25 };39Object.defineProperty(obj2, 'name', { enumerable: false });40var descriptor = Object.getOwnPropertyDescriptors(obj);41var descriptor2 = Object.getOwnPropertyDescriptors(obj2);42describe('assertOwnPropertyDescriptors', function() {43 it('should check the property descriptor', function() {44 assert.ownPropertyDescriptors(obj, descriptor);45 });46 it('should check the property descriptor', function() {47 assert.ownPropertyDescriptors(obj2, descriptor2);48 });49});50var chai = require('chai

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chai automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful