You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6141 lines
155 KiB

4 years ago
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.chai = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. module.exports = require('./lib/chai');
  3. },{"./lib/chai":2}],2:[function(require,module,exports){
  4. /*!
  5. * chai
  6. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  7. * MIT Licensed
  8. */
  9. var used = []
  10. , exports = module.exports = {};
  11. /*!
  12. * Chai version
  13. */
  14. exports.version = '3.5.0';
  15. /*!
  16. * Assertion Error
  17. */
  18. exports.AssertionError = require('assertion-error');
  19. /*!
  20. * Utils for plugins (not exported)
  21. */
  22. var util = require('./chai/utils');
  23. /**
  24. * # .use(function)
  25. *
  26. * Provides a way to extend the internals of Chai
  27. *
  28. * @param {Function}
  29. * @returns {this} for chaining
  30. * @api public
  31. */
  32. exports.use = function (fn) {
  33. if (!~used.indexOf(fn)) {
  34. fn(this, util);
  35. used.push(fn);
  36. }
  37. return this;
  38. };
  39. /*!
  40. * Utility Functions
  41. */
  42. exports.util = util;
  43. /*!
  44. * Configuration
  45. */
  46. var config = require('./chai/config');
  47. exports.config = config;
  48. /*!
  49. * Primary `Assertion` prototype
  50. */
  51. var assertion = require('./chai/assertion');
  52. exports.use(assertion);
  53. /*!
  54. * Core Assertions
  55. */
  56. var core = require('./chai/core/assertions');
  57. exports.use(core);
  58. /*!
  59. * Expect interface
  60. */
  61. var expect = require('./chai/interface/expect');
  62. exports.use(expect);
  63. /*!
  64. * Should interface
  65. */
  66. var should = require('./chai/interface/should');
  67. exports.use(should);
  68. /*!
  69. * Assert interface
  70. */
  71. var assert = require('./chai/interface/assert');
  72. exports.use(assert);
  73. },{"./chai/assertion":3,"./chai/config":4,"./chai/core/assertions":5,"./chai/interface/assert":6,"./chai/interface/expect":7,"./chai/interface/should":8,"./chai/utils":22,"assertion-error":30}],3:[function(require,module,exports){
  74. /*!
  75. * chai
  76. * http://chaijs.com
  77. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  78. * MIT Licensed
  79. */
  80. var config = require('./config');
  81. module.exports = function (_chai, util) {
  82. /*!
  83. * Module dependencies.
  84. */
  85. var AssertionError = _chai.AssertionError
  86. , flag = util.flag;
  87. /*!
  88. * Module export.
  89. */
  90. _chai.Assertion = Assertion;
  91. /*!
  92. * Assertion Constructor
  93. *
  94. * Creates object for chaining.
  95. *
  96. * @api private
  97. */
  98. function Assertion (obj, msg, stack) {
  99. flag(this, 'ssfi', stack || arguments.callee);
  100. flag(this, 'object', obj);
  101. flag(this, 'message', msg);
  102. }
  103. Object.defineProperty(Assertion, 'includeStack', {
  104. get: function() {
  105. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  106. return config.includeStack;
  107. },
  108. set: function(value) {
  109. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  110. config.includeStack = value;
  111. }
  112. });
  113. Object.defineProperty(Assertion, 'showDiff', {
  114. get: function() {
  115. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  116. return config.showDiff;
  117. },
  118. set: function(value) {
  119. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  120. config.showDiff = value;
  121. }
  122. });
  123. Assertion.addProperty = function (name, fn) {
  124. util.addProperty(this.prototype, name, fn);
  125. };
  126. Assertion.addMethod = function (name, fn) {
  127. util.addMethod(this.prototype, name, fn);
  128. };
  129. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  130. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  131. };
  132. Assertion.overwriteProperty = function (name, fn) {
  133. util.overwriteProperty(this.prototype, name, fn);
  134. };
  135. Assertion.overwriteMethod = function (name, fn) {
  136. util.overwriteMethod(this.prototype, name, fn);
  137. };
  138. Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
  139. util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
  140. };
  141. /**
  142. * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
  143. *
  144. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  145. *
  146. * @name assert
  147. * @param {Philosophical} expression to be tested
  148. * @param {String|Function} message or function that returns message to display if expression fails
  149. * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
  150. * @param {Mixed} expected value (remember to check for negation)
  151. * @param {Mixed} actual (optional) will default to `this.obj`
  152. * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
  153. * @api private
  154. */
  155. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  156. var ok = util.test(this, arguments);
  157. if (true !== showDiff) showDiff = false;
  158. if (true !== config.showDiff) showDiff = false;
  159. if (!ok) {
  160. var msg = util.getMessage(this, arguments)
  161. , actual = util.getActual(this, arguments);
  162. throw new AssertionError(msg, {
  163. actual: actual
  164. , expected: expected
  165. , showDiff: showDiff
  166. }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
  167. }
  168. };
  169. /*!
  170. * ### ._obj
  171. *
  172. * Quick reference to stored `actual` value for plugin developers.
  173. *
  174. * @api private
  175. */
  176. Object.defineProperty(Assertion.prototype, '_obj',
  177. { get: function () {
  178. return flag(this, 'object');
  179. }
  180. , set: function (val) {
  181. flag(this, 'object', val);
  182. }
  183. });
  184. };
  185. },{"./config":4}],4:[function(require,module,exports){
  186. module.exports = {
  187. /**
  188. * ### config.includeStack
  189. *
  190. * User configurable property, influences whether stack trace
  191. * is included in Assertion error message. Default of false
  192. * suppresses stack trace in the error message.
  193. *
  194. * chai.config.includeStack = true; // enable stack on error
  195. *
  196. * @param {Boolean}
  197. * @api public
  198. */
  199. includeStack: false,
  200. /**
  201. * ### config.showDiff
  202. *
  203. * User configurable property, influences whether or not
  204. * the `showDiff` flag should be included in the thrown
  205. * AssertionErrors. `false` will always be `false`; `true`
  206. * will be true when the assertion has requested a diff
  207. * be shown.
  208. *
  209. * @param {Boolean}
  210. * @api public
  211. */
  212. showDiff: true,
  213. /**
  214. * ### config.truncateThreshold
  215. *
  216. * User configurable property, sets length threshold for actual and
  217. * expected values in assertion errors. If this threshold is exceeded, for
  218. * example for large data structures, the value is replaced with something
  219. * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
  220. *
  221. * Set it to zero if you want to disable truncating altogether.
  222. *
  223. * This is especially userful when doing assertions on arrays: having this
  224. * set to a reasonable large value makes the failure messages readily
  225. * inspectable.
  226. *
  227. * chai.config.truncateThreshold = 0; // disable truncating
  228. *
  229. * @param {Number}
  230. * @api public
  231. */
  232. truncateThreshold: 40
  233. };
  234. },{}],5:[function(require,module,exports){
  235. /*!
  236. * chai
  237. * http://chaijs.com
  238. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  239. * MIT Licensed
  240. */
  241. module.exports = function (chai, _) {
  242. var Assertion = chai.Assertion
  243. , toString = Object.prototype.toString
  244. , flag = _.flag;
  245. /**
  246. * ### Language Chains
  247. *
  248. * The following are provided as chainable getters to
  249. * improve the readability of your assertions. They
  250. * do not provide testing capabilities unless they
  251. * have been overwritten by a plugin.
  252. *
  253. * **Chains**
  254. *
  255. * - to
  256. * - be
  257. * - been
  258. * - is
  259. * - that
  260. * - which
  261. * - and
  262. * - has
  263. * - have
  264. * - with
  265. * - at
  266. * - of
  267. * - same
  268. *
  269. * @name language chains
  270. * @namespace BDD
  271. * @api public
  272. */
  273. [ 'to', 'be', 'been'
  274. , 'is', 'and', 'has', 'have'
  275. , 'with', 'that', 'which', 'at'
  276. , 'of', 'same' ].forEach(function (chain) {
  277. Assertion.addProperty(chain, function () {
  278. return this;
  279. });
  280. });
  281. /**
  282. * ### .not
  283. *
  284. * Negates any of assertions following in the chain.
  285. *
  286. * expect(foo).to.not.equal('bar');
  287. * expect(goodFn).to.not.throw(Error);
  288. * expect({ foo: 'baz' }).to.have.property('foo')
  289. * .and.not.equal('bar');
  290. *
  291. * @name not
  292. * @namespace BDD
  293. * @api public
  294. */
  295. Assertion.addProperty('not', function () {
  296. flag(this, 'negate', true);
  297. });
  298. /**
  299. * ### .deep
  300. *
  301. * Sets the `deep` flag, later used by the `equal` and
  302. * `property` assertions.
  303. *
  304. * expect(foo).to.deep.equal({ bar: 'baz' });
  305. * expect({ foo: { bar: { baz: 'quux' } } })
  306. * .to.have.deep.property('foo.bar.baz', 'quux');
  307. *
  308. * `.deep.property` special characters can be escaped
  309. * by adding two slashes before the `.` or `[]`.
  310. *
  311. * var deepCss = { '.link': { '[target]': 42 }};
  312. * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
  313. *
  314. * @name deep
  315. * @namespace BDD
  316. * @api public
  317. */
  318. Assertion.addProperty('deep', function () {
  319. flag(this, 'deep', true);
  320. });
  321. /**
  322. * ### .any
  323. *
  324. * Sets the `any` flag, (opposite of the `all` flag)
  325. * later used in the `keys` assertion.
  326. *
  327. * expect(foo).to.have.any.keys('bar', 'baz');
  328. *
  329. * @name any
  330. * @namespace BDD
  331. * @api public
  332. */
  333. Assertion.addProperty('any', function () {
  334. flag(this, 'any', true);
  335. flag(this, 'all', false)
  336. });
  337. /**
  338. * ### .all
  339. *
  340. * Sets the `all` flag (opposite of the `any` flag)
  341. * later used by the `keys` assertion.
  342. *
  343. * expect(foo).to.have.all.keys('bar', 'baz');
  344. *
  345. * @name all
  346. * @namespace BDD
  347. * @api public
  348. */
  349. Assertion.addProperty('all', function () {
  350. flag(this, 'all', true);
  351. flag(this, 'any', false);
  352. });
  353. /**
  354. * ### .a(type)
  355. *
  356. * The `a` and `an` assertions are aliases that can be
  357. * used either as language chains or to assert a value's
  358. * type.
  359. *
  360. * // typeof
  361. * expect('test').to.be.a('string');
  362. * expect({ foo: 'bar' }).to.be.an('object');
  363. * expect(null).to.be.a('null');
  364. * expect(undefined).to.be.an('undefined');
  365. * expect(new Error).to.be.an('error');
  366. * expect(new Promise).to.be.a('promise');
  367. * expect(new Float32Array()).to.be.a('float32array');
  368. * expect(Symbol()).to.be.a('symbol');
  369. *
  370. * // es6 overrides
  371. * expect({[Symbol.toStringTag]:()=>'foo'}).to.be.a('foo');
  372. *
  373. * // language chain
  374. * expect(foo).to.be.an.instanceof(Foo);
  375. *
  376. * @name a
  377. * @alias an
  378. * @param {String} type
  379. * @param {String} message _optional_
  380. * @namespace BDD
  381. * @api public
  382. */
  383. function an (type, msg) {
  384. if (msg) flag(this, 'message', msg);
  385. type = type.toLowerCase();
  386. var obj = flag(this, 'object')
  387. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  388. this.assert(
  389. type === _.type(obj)
  390. , 'expected #{this} to be ' + article + type
  391. , 'expected #{this} not to be ' + article + type
  392. );
  393. }
  394. Assertion.addChainableMethod('an', an);
  395. Assertion.addChainableMethod('a', an);
  396. /**
  397. * ### .include(value)
  398. *
  399. * The `include` and `contain` assertions can be used as either property
  400. * based language chains or as methods to assert the inclusion of an object
  401. * in an array or a substring in a string. When used as language chains,
  402. * they toggle the `contains` flag for the `keys` assertion.
  403. *
  404. * expect([1,2,3]).to.include(2);
  405. * expect('foobar').to.contain('foo');
  406. * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
  407. *
  408. * @name include
  409. * @alias contain
  410. * @alias includes
  411. * @alias contains
  412. * @param {Object|String|Number} obj
  413. * @param {String} message _optional_
  414. * @namespace BDD
  415. * @api public
  416. */
  417. function includeChainingBehavior () {
  418. flag(this, 'contains', true);
  419. }
  420. function include (val, msg) {
  421. _.expectTypes(this, ['array', 'object', 'string']);
  422. if (msg) flag(this, 'message', msg);
  423. var obj = flag(this, 'object');
  424. var expected = false;
  425. if (_.type(obj) === 'array' && _.type(val) === 'object') {
  426. for (var i in obj) {
  427. if (_.eql(obj[i], val)) {
  428. expected = true;
  429. break;
  430. }
  431. }
  432. } else if (_.type(val) === 'object') {
  433. if (!flag(this, 'negate')) {
  434. for (var k in val) new Assertion(obj).property(k, val[k]);
  435. return;
  436. }
  437. var subset = {};
  438. for (var k in val) subset[k] = obj[k];
  439. expected = _.eql(subset, val);
  440. } else {
  441. expected = (obj != undefined) && ~obj.indexOf(val);
  442. }
  443. this.assert(
  444. expected
  445. , 'expected #{this} to include ' + _.inspect(val)
  446. , 'expected #{this} to not include ' + _.inspect(val));
  447. }
  448. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  449. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  450. Assertion.addChainableMethod('contains', include, includeChainingBehavior);
  451. Assertion.addChainableMethod('includes', include, includeChainingBehavior);
  452. /**
  453. * ### .ok
  454. *
  455. * Asserts that the target is truthy.
  456. *
  457. * expect('everything').to.be.ok;
  458. * expect(1).to.be.ok;
  459. * expect(false).to.not.be.ok;
  460. * expect(undefined).to.not.be.ok;
  461. * expect(null).to.not.be.ok;
  462. *
  463. * @name ok
  464. * @namespace BDD
  465. * @api public
  466. */
  467. Assertion.addProperty('ok', function () {
  468. this.assert(
  469. flag(this, 'object')
  470. , 'expected #{this} to be truthy'
  471. , 'expected #{this} to be falsy');
  472. });
  473. /**
  474. * ### .true
  475. *
  476. * Asserts that the target is `true`.
  477. *
  478. * expect(true).to.be.true;
  479. * expect(1).to.not.be.true;
  480. *
  481. * @name true
  482. * @namespace BDD
  483. * @api public
  484. */
  485. Assertion.addProperty('true', function () {
  486. this.assert(
  487. true === flag(this, 'object')
  488. , 'expected #{this} to be true'
  489. , 'expected #{this} to be false'
  490. , this.negate ? false : true
  491. );
  492. });
  493. /**
  494. * ### .false
  495. *
  496. * Asserts that the target is `false`.
  497. *
  498. * expect(false).to.be.false;
  499. * expect(0).to.not.be.false;
  500. *
  501. * @name false
  502. * @namespace BDD
  503. * @api public
  504. */
  505. Assertion.addProperty('false', function () {
  506. this.assert(
  507. false === flag(this, 'object')
  508. , 'expected #{this} to be false'
  509. , 'expected #{this} to be true'
  510. , this.negate ? true : false
  511. );
  512. });
  513. /**
  514. * ### .null
  515. *
  516. * Asserts that the target is `null`.
  517. *
  518. * expect(null).to.be.null;
  519. * expect(undefined).to.not.be.null;
  520. *
  521. * @name null
  522. * @namespace BDD
  523. * @api public
  524. */
  525. Assertion.addProperty('null', function () {
  526. this.assert(
  527. null === flag(this, 'object')
  528. , 'expected #{this} to be null'
  529. , 'expected #{this} not to be null'
  530. );
  531. });
  532. /**
  533. * ### .undefined
  534. *
  535. * Asserts that the target is `undefined`.
  536. *
  537. * expect(undefined).to.be.undefined;
  538. * expect(null).to.not.be.undefined;
  539. *
  540. * @name undefined
  541. * @namespace BDD
  542. * @api public
  543. */
  544. Assertion.addProperty('undefined', function () {
  545. this.assert(
  546. undefined === flag(this, 'object')
  547. , 'expected #{this} to be undefined'
  548. , 'expected #{this} not to be undefined'
  549. );
  550. });
  551. /**
  552. * ### .NaN
  553. * Asserts that the target is `NaN`.
  554. *
  555. * expect('foo').to.be.NaN;
  556. * expect(4).not.to.be.NaN;
  557. *
  558. * @name NaN
  559. * @namespace BDD
  560. * @api public
  561. */
  562. Assertion.addProperty('NaN', function () {
  563. this.assert(
  564. isNaN(flag(this, 'object'))
  565. , 'expected #{this} to be NaN'
  566. , 'expected #{this} not to be NaN'
  567. );
  568. });
  569. /**
  570. * ### .exist
  571. *
  572. * Asserts that the target is neither `null` nor `undefined`.
  573. *
  574. * var foo = 'hi'
  575. * , bar = null
  576. * , baz;
  577. *
  578. * expect(foo).to.exist;
  579. * expect(bar).to.not.exist;
  580. * expect(baz).to.not.exist;
  581. *
  582. * @name exist
  583. * @namespace BDD
  584. * @api public
  585. */
  586. Assertion.addProperty('exist', function () {
  587. this.assert(
  588. null != flag(this, 'object')
  589. , 'expected #{this} to exist'
  590. , 'expected #{this} to not exist'
  591. );
  592. });
  593. /**
  594. * ### .empty
  595. *
  596. * Asserts that the target's length is `0`. For arrays and strings, it checks
  597. * the `length` property. For objects, it gets the count of
  598. * enumerable keys.
  599. *
  600. * expect([]).to.be.empty;
  601. * expect('').to.be.empty;
  602. * expect({}).to.be.empty;
  603. *
  604. * @name empty
  605. * @namespace BDD
  606. * @api public
  607. */
  608. Assertion.addProperty('empty', function () {
  609. var obj = flag(this, 'object')
  610. , expected = obj;
  611. if (Array.isArray(obj) || 'string' === typeof object) {
  612. expected = obj.length;
  613. } else if (typeof obj === 'object') {
  614. expected = Object.keys(obj).length;
  615. }
  616. this.assert(
  617. !expected
  618. , 'expected #{this} to be empty'
  619. , 'expected #{this} not to be empty'
  620. );
  621. });
  622. /**
  623. * ### .arguments
  624. *
  625. * Asserts that the target is an arguments object.
  626. *
  627. * function test () {
  628. * expect(arguments).to.be.arguments;
  629. * }
  630. *
  631. * @name arguments
  632. * @alias Arguments
  633. * @namespace BDD
  634. * @api public
  635. */
  636. function checkArguments () {
  637. var obj = flag(this, 'object')
  638. , type = Object.prototype.toString.call(obj);
  639. this.assert(
  640. '[object Arguments]' === type
  641. , 'expected #{this} to be arguments but got ' + type
  642. , 'expected #{this} to not be arguments'
  643. );
  644. }
  645. Assertion.addProperty('arguments', checkArguments);
  646. Assertion.addProperty('Arguments', checkArguments);
  647. /**
  648. * ### .equal(value)
  649. *
  650. * Asserts that the target is strictly equal (`===`) to `value`.
  651. * Alternately, if the `deep` flag is set, asserts that
  652. * the target is deeply equal to `value`.
  653. *
  654. * expect('hello').to.equal('hello');
  655. * expect(42).to.equal(42);
  656. * expect(1).to.not.equal(true);
  657. * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
  658. * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
  659. *
  660. * @name equal
  661. * @alias equals
  662. * @alias eq
  663. * @alias deep.equal
  664. * @param {Mixed} value
  665. * @param {String} message _optional_
  666. * @namespace BDD
  667. * @api public
  668. */
  669. function assertEqual (val, msg) {
  670. if (msg) flag(this, 'message', msg);
  671. var obj = flag(this, 'object');
  672. if (flag(this, 'deep')) {
  673. return this.eql(val);
  674. } else {
  675. this.assert(
  676. val === obj
  677. , 'expected #{this} to equal #{exp}'
  678. , 'expected #{this} to not equal #{exp}'
  679. , val
  680. , this._obj
  681. , true
  682. );
  683. }
  684. }
  685. Assertion.addMethod('equal', assertEqual);
  686. Assertion.addMethod('equals', assertEqual);
  687. Assertion.addMethod('eq', assertEqual);
  688. /**
  689. * ### .eql(value)
  690. *
  691. * Asserts that the target is deeply equal to `value`.
  692. *
  693. * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
  694. * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
  695. *
  696. * @name eql
  697. * @alias eqls
  698. * @param {Mixed} value
  699. * @param {String} message _optional_
  700. * @namespace BDD
  701. * @api public
  702. */
  703. function assertEql(obj, msg) {
  704. if (msg) flag(this, 'message', msg);
  705. this.assert(
  706. _.eql(obj, flag(this, 'object'))
  707. , 'expected #{this} to deeply equal #{exp}'
  708. , 'expected #{this} to not deeply equal #{exp}'
  709. , obj
  710. , this._obj
  711. , true
  712. );
  713. }
  714. Assertion.addMethod('eql', assertEql);
  715. Assertion.addMethod('eqls', assertEql);
  716. /**
  717. * ### .above(value)
  718. *
  719. * Asserts that the target is greater than `value`.
  720. *
  721. * expect(10).to.be.above(5);
  722. *
  723. * Can also be used in conjunction with `length` to
  724. * assert a minimum length. The benefit being a
  725. * more informative error message than if the length
  726. * was supplied directly.
  727. *
  728. * expect('foo').to.have.length.above(2);
  729. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  730. *
  731. * @name above
  732. * @alias gt
  733. * @alias greaterThan
  734. * @param {Number} value
  735. * @param {String} message _optional_
  736. * @namespace BDD
  737. * @api public
  738. */
  739. function assertAbove (n, msg) {
  740. if (msg) flag(this, 'message', msg);
  741. var obj = flag(this, 'object');
  742. if (flag(this, 'doLength')) {
  743. new Assertion(obj, msg).to.have.property('length');
  744. var len = obj.length;
  745. this.assert(
  746. len > n
  747. , 'expected #{this} to have a length above #{exp} but got #{act}'
  748. , 'expected #{this} to not have a length above #{exp}'
  749. , n
  750. , len
  751. );
  752. } else {
  753. this.assert(
  754. obj > n
  755. , 'expected #{this} to be above ' + n
  756. , 'expected #{this} to be at most ' + n
  757. );
  758. }
  759. }
  760. Assertion.addMethod('above', assertAbove);
  761. Assertion.addMethod('gt', assertAbove);
  762. Assertion.addMethod('greaterThan', assertAbove);
  763. /**
  764. * ### .least(value)
  765. *
  766. * Asserts that the target is greater than or equal to `value`.
  767. *
  768. * expect(10).to.be.at.least(10);
  769. *
  770. * Can also be used in conjunction with `length` to
  771. * assert a minimum length. The benefit being a
  772. * more informative error message than if the length
  773. * was supplied directly.
  774. *
  775. * expect('foo').to.have.length.of.at.least(2);
  776. * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
  777. *
  778. * @name least
  779. * @alias gte
  780. * @param {Number} value
  781. * @param {String} message _optional_
  782. * @namespace BDD
  783. * @api public
  784. */
  785. function assertLeast (n, msg) {
  786. if (msg) flag(this, 'message', msg);
  787. var obj = flag(this, 'object');
  788. if (flag(this, 'doLength')) {
  789. new Assertion(obj, msg).to.have.property('length');
  790. var len = obj.length;
  791. this.assert(
  792. len >= n
  793. , 'expected #{this} to have a length at least #{exp} but got #{act}'
  794. , 'expected #{this} to have a length below #{exp}'
  795. , n
  796. , len
  797. );
  798. } else {
  799. this.assert(
  800. obj >= n
  801. , 'expected #{this} to be at least ' + n
  802. , 'expected #{this} to be below ' + n
  803. );
  804. }
  805. }
  806. Assertion.addMethod('least', assertLeast);
  807. Assertion.addMethod('gte', assertLeast);
  808. /**
  809. * ### .below(value)
  810. *
  811. * Asserts that the target is less than `value`.
  812. *
  813. * expect(5).to.be.below(10);
  814. *
  815. * Can also be used in conjunction with `length` to
  816. * assert a maximum length. The benefit being a
  817. * more informative error message than if the length
  818. * was supplied directly.
  819. *
  820. * expect('foo').to.have.length.below(4);
  821. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  822. *
  823. * @name below
  824. * @alias lt
  825. * @alias lessThan
  826. * @param {Number} value
  827. * @param {String} message _optional_
  828. * @namespace BDD
  829. * @api public
  830. */
  831. function assertBelow (n, msg) {
  832. if (msg) flag(this, 'message', msg);
  833. var obj = flag(this, 'object');
  834. if (flag(this, 'doLength')) {
  835. new Assertion(obj, msg).to.have.property('length');
  836. var len = obj.length;
  837. this.assert(
  838. len < n
  839. , 'expected #{this} to have a length below #{exp} but got #{act}'
  840. , 'expected #{this} to not have a length below #{exp}'
  841. , n
  842. , len
  843. );
  844. } else {
  845. this.assert(
  846. obj < n
  847. , 'expected #{this} to be below ' + n
  848. , 'expected #{this} to be at least ' + n
  849. );
  850. }
  851. }
  852. Assertion.addMethod('below', assertBelow);
  853. Assertion.addMethod('lt', assertBelow);
  854. Assertion.addMethod('lessThan', assertBelow);
  855. /**
  856. * ### .most(value)
  857. *
  858. * Asserts that the target is less than or equal to `value`.
  859. *
  860. * expect(5).to.be.at.most(5);
  861. *
  862. * Can also be used in conjunction with `length` to
  863. * assert a maximum length. The benefit being a
  864. * more informative error message than if the length
  865. * was supplied directly.
  866. *
  867. * expect('foo').to.have.length.of.at.most(4);
  868. * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
  869. *
  870. * @name most
  871. * @alias lte
  872. * @param {Number} value
  873. * @param {String} message _optional_
  874. * @namespace BDD
  875. * @api public
  876. */
  877. function assertMost (n, msg) {
  878. if (msg) flag(this, 'message', msg);
  879. var obj = flag(this, 'object');
  880. if (flag(this, 'doLength')) {
  881. new Assertion(obj, msg).to.have.property('length');
  882. var len = obj.length;
  883. this.assert(
  884. len <= n
  885. , 'expected #{this} to have a length at most #{exp} but got #{act}'
  886. , 'expected #{this} to have a length above #{exp}'
  887. , n
  888. , len
  889. );
  890. } else {
  891. this.assert(
  892. obj <= n
  893. , 'expected #{this} to be at most ' + n
  894. , 'expected #{this} to be above ' + n
  895. );
  896. }
  897. }
  898. Assertion.addMethod('most', assertMost);
  899. Assertion.addMethod('lte', assertMost);
  900. /**
  901. * ### .within(start, finish)
  902. *
  903. * Asserts that the target is within a range.
  904. *
  905. * expect(7).to.be.within(5,10);
  906. *
  907. * Can also be used in conjunction with `length` to
  908. * assert a length range. The benefit being a
  909. * more informative error message than if the length
  910. * was supplied directly.
  911. *
  912. * expect('foo').to.have.length.within(2,4);
  913. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  914. *
  915. * @name within
  916. * @param {Number} start lowerbound inclusive
  917. * @param {Number} finish upperbound inclusive
  918. * @param {String} message _optional_
  919. * @namespace BDD
  920. * @api public
  921. */
  922. Assertion.addMethod('within', function (start, finish, msg) {
  923. if (msg) flag(this, 'message', msg);
  924. var obj = flag(this, 'object')
  925. , range = start + '..' + finish;
  926. if (flag(this, 'doLength')) {
  927. new Assertion(obj, msg).to.have.property('length');
  928. var len = obj.length;
  929. this.assert(
  930. len >= start && len <= finish
  931. , 'expected #{this} to have a length within ' + range
  932. , 'expected #{this} to not have a length within ' + range
  933. );
  934. } else {
  935. this.assert(
  936. obj >= start && obj <= finish
  937. , 'expected #{this} to be within ' + range
  938. , 'expected #{this} to not be within ' + range
  939. );
  940. }
  941. });
  942. /**
  943. * ### .instanceof(constructor)
  944. *
  945. * Asserts that the target is an instance of `constructor`.
  946. *
  947. * var Tea = function (name) { this.name = name; }
  948. * , Chai = new Tea('chai');
  949. *
  950. * expect(Chai).to.be.an.instanceof(Tea);
  951. * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
  952. *
  953. * @name instanceof
  954. * @param {Constructor} constructor
  955. * @param {String} message _optional_
  956. * @alias instanceOf
  957. * @namespace BDD
  958. * @api public
  959. */
  960. function assertInstanceOf (constructor, msg) {
  961. if (msg) flag(this, 'message', msg);
  962. var name = _.getName(constructor);
  963. this.assert(
  964. flag(this, 'object') instanceof constructor
  965. , 'expected #{this} to be an instance of ' + name
  966. , 'expected #{this} to not be an instance of ' + name
  967. );
  968. };
  969. Assertion.addMethod('instanceof', assertInstanceOf);
  970. Assertion.addMethod('instanceOf', assertInstanceOf);
  971. /**
  972. * ### .property(name, [value])
  973. *
  974. * Asserts that the target has a property `name`, optionally asserting that
  975. * the value of that property is strictly equal to `value`.
  976. * If the `deep` flag is set, you can use dot- and bracket-notation for deep
  977. * references into objects and arrays.
  978. *
  979. * // simple referencing
  980. * var obj = { foo: 'bar' };
  981. * expect(obj).to.have.property('foo');
  982. * expect(obj).to.have.property('foo', 'bar');
  983. *
  984. * // deep referencing
  985. * var deepObj = {
  986. * green: { tea: 'matcha' }
  987. * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
  988. * };
  989. *
  990. * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
  991. * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
  992. * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
  993. *
  994. * You can also use an array as the starting point of a `deep.property`
  995. * assertion, or traverse nested arrays.
  996. *
  997. * var arr = [
  998. * [ 'chai', 'matcha', 'konacha' ]
  999. * , [ { tea: 'chai' }
  1000. * , { tea: 'matcha' }
  1001. * , { tea: 'konacha' } ]
  1002. * ];
  1003. *
  1004. * expect(arr).to.have.deep.property('[0][1]', 'matcha');
  1005. * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
  1006. *
  1007. * Furthermore, `property` changes the subject of the assertion
  1008. * to be the value of that property from the original object. This
  1009. * permits for further chainable assertions on that property.
  1010. *
  1011. * expect(obj).to.have.property('foo')
  1012. * .that.is.a('string');
  1013. * expect(deepObj).to.have.property('green')
  1014. * .that.is.an('object')
  1015. * .that.deep.equals({ tea: 'matcha' });
  1016. * expect(deepObj).to.have.property('teas')
  1017. * .that.is.an('array')
  1018. * .with.deep.property('[2]')
  1019. * .that.deep.equals({ tea: 'konacha' });
  1020. *
  1021. * Note that dots and bracket in `name` must be backslash-escaped when
  1022. * the `deep` flag is set, while they must NOT be escaped when the `deep`
  1023. * flag is not set.
  1024. *
  1025. * // simple referencing
  1026. * var css = { '.link[target]': 42 };
  1027. * expect(css).to.have.property('.link[target]', 42);
  1028. *
  1029. * // deep referencing
  1030. * var deepCss = { '.link': { '[target]': 42 }};
  1031. * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
  1032. *
  1033. * @name property
  1034. * @alias deep.property
  1035. * @param {String} name
  1036. * @param {Mixed} value (optional)
  1037. * @param {String} message _optional_
  1038. * @returns value of property for chaining
  1039. * @namespace BDD
  1040. * @api public
  1041. */
  1042. Assertion.addMethod('property', function (name, val, msg) {
  1043. if (msg) flag(this, 'message', msg);
  1044. var isDeep = !!flag(this, 'deep')
  1045. , descriptor = isDeep ? 'deep property ' : 'property '
  1046. , negate = flag(this, 'negate')
  1047. , obj = flag(this, 'object')
  1048. , pathInfo = isDeep ? _.getPathInfo(name, obj) : null
  1049. , hasProperty = isDeep
  1050. ? pathInfo.exists
  1051. : _.hasProperty(name, obj)
  1052. , value = isDeep
  1053. ? pathInfo.value
  1054. : obj[name];
  1055. if (negate && arguments.length > 1) {
  1056. if (undefined === value) {
  1057. msg = (msg != null) ? msg + ': ' : '';
  1058. throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
  1059. }
  1060. } else {
  1061. this.assert(
  1062. hasProperty
  1063. , 'expected #{this} to have a ' + descriptor + _.inspect(name)
  1064. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  1065. }
  1066. if (arguments.length > 1) {
  1067. this.assert(
  1068. val === value
  1069. , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  1070. , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
  1071. , val
  1072. , value
  1073. );
  1074. }
  1075. flag(this, 'object', value);
  1076. });
  1077. /**
  1078. * ### .ownProperty(name)
  1079. *
  1080. * Asserts that the target has an own property `name`.
  1081. *
  1082. * expect('test').to.have.ownProperty('length');
  1083. *
  1084. * @name ownProperty
  1085. * @alias haveOwnProperty
  1086. * @param {String} name
  1087. * @param {String} message _optional_
  1088. * @namespace BDD
  1089. * @api public
  1090. */
  1091. function assertOwnProperty (name, msg) {
  1092. if (msg) flag(this, 'message', msg);
  1093. var obj = flag(this, 'object');
  1094. this.assert(
  1095. obj.hasOwnProperty(name)
  1096. , 'expected #{this} to have own property ' + _.inspect(name)
  1097. , 'expected #{this} to not have own property ' + _.inspect(name)
  1098. );
  1099. }
  1100. Assertion.addMethod('ownProperty', assertOwnProperty);
  1101. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  1102. /**
  1103. * ### .ownPropertyDescriptor(name[, descriptor[, message]])
  1104. *
  1105. * Asserts that the target has an own property descriptor `name`, that optionally matches `descriptor`.
  1106. *
  1107. * expect('test').to.have.ownPropertyDescriptor('length');
  1108. * expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });
  1109. * expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });
  1110. * expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);
  1111. * expect('test').ownPropertyDescriptor('length').to.have.keys('value');
  1112. *
  1113. * @name ownPropertyDescriptor
  1114. * @alias haveOwnPropertyDescriptor
  1115. * @param {String} name
  1116. * @param {Object} descriptor _optional_
  1117. * @param {String} message _optional_
  1118. * @namespace BDD
  1119. * @api public
  1120. */
  1121. function assertOwnPropertyDescriptor (name, descriptor, msg) {
  1122. if (typeof descriptor === 'string') {
  1123. msg = descriptor;
  1124. descriptor = null;
  1125. }
  1126. if (msg) flag(this, 'message', msg);
  1127. var obj = flag(this, 'object');
  1128. var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
  1129. if (actualDescriptor && descriptor) {
  1130. this.assert(
  1131. _.eql(descriptor, actualDescriptor)
  1132. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
  1133. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
  1134. , descriptor
  1135. , actualDescriptor
  1136. , true
  1137. );
  1138. } else {
  1139. this.assert(
  1140. actualDescriptor
  1141. , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)
  1142. , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)
  1143. );
  1144. }
  1145. flag(this, 'object', actualDescriptor);
  1146. }
  1147. Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
  1148. Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
  1149. /**
  1150. * ### .length
  1151. *
  1152. * Sets the `doLength` flag later used as a chain precursor to a value
  1153. * comparison for the `length` property.
  1154. *
  1155. * expect('foo').to.have.length.above(2);
  1156. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  1157. * expect('foo').to.have.length.below(4);
  1158. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  1159. * expect('foo').to.have.length.within(2,4);
  1160. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  1161. *
  1162. * *Deprecation notice:* Using `length` as an assertion will be deprecated
  1163. * in version 2.4.0 and removed in 3.0.0. Code using the old style of
  1164. * asserting for `length` property value using `length(value)` should be
  1165. * switched to use `lengthOf(value)` instead.
  1166. *
  1167. * @name length
  1168. * @namespace BDD
  1169. * @api public
  1170. */
  1171. /**
  1172. * ### .lengthOf(value[, message])
  1173. *
  1174. * Asserts that the target's `length` property has
  1175. * the expected value.
  1176. *
  1177. * expect([ 1, 2, 3]).to.have.lengthOf(3);
  1178. * expect('foobar').to.have.lengthOf(6);
  1179. *
  1180. * @name lengthOf
  1181. * @param {Number} length
  1182. * @param {String} message _optional_
  1183. * @namespace BDD
  1184. * @api public
  1185. */
  1186. function assertLengthChain () {
  1187. flag(this, 'doLength', true);
  1188. }
  1189. function assertLength (n, msg) {
  1190. if (msg) flag(this, 'message', msg);
  1191. var obj = flag(this, 'object');
  1192. new Assertion(obj, msg).to.have.property('length');
  1193. var len = obj.length;
  1194. this.assert(
  1195. len == n
  1196. , 'expected #{this} to have a length of #{exp} but got #{act}'
  1197. , 'expected #{this} to not have a length of #{act}'
  1198. , n
  1199. , len
  1200. );
  1201. }
  1202. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  1203. Assertion.addMethod('lengthOf', assertLength);
  1204. /**
  1205. * ### .match(regexp)
  1206. *
  1207. * Asserts that the target matches a regular expression.
  1208. *
  1209. * expect('foobar').to.match(/^foo/);
  1210. *
  1211. * @name match
  1212. * @alias matches
  1213. * @param {RegExp} RegularExpression
  1214. * @param {String} message _optional_
  1215. * @namespace BDD
  1216. * @api public
  1217. */
  1218. function assertMatch(re, msg) {
  1219. if (msg) flag(this, 'message', msg);
  1220. var obj = flag(this, 'object');
  1221. this.assert(
  1222. re.exec(obj)
  1223. , 'expected #{this} to match ' + re
  1224. , 'expected #{this} not to match ' + re
  1225. );
  1226. }
  1227. Assertion.addMethod('match', assertMatch);
  1228. Assertion.addMethod('matches', assertMatch);
  1229. /**
  1230. * ### .string(string)
  1231. *
  1232. * Asserts that the string target contains another string.
  1233. *
  1234. * expect('foobar').to.have.string('bar');
  1235. *
  1236. * @name string
  1237. * @param {String} string
  1238. * @param {String} message _optional_
  1239. * @namespace BDD
  1240. * @api public
  1241. */
  1242. Assertion.addMethod('string', function (str, msg) {
  1243. if (msg) flag(this, 'message', msg);
  1244. var obj = flag(this, 'object');
  1245. new Assertion(obj, msg).is.a('string');
  1246. this.assert(
  1247. ~obj.indexOf(str)
  1248. , 'expected #{this} to contain ' + _.inspect(str)
  1249. , 'expected #{this} to not contain ' + _.inspect(str)
  1250. );
  1251. });
  1252. /**
  1253. * ### .keys(key1, [key2], [...])
  1254. *
  1255. * Asserts that the target contains any or all of the passed-in keys.
  1256. * Use in combination with `any`, `all`, `contains`, or `have` will affect
  1257. * what will pass.
  1258. *
  1259. * When used in conjunction with `any`, at least one key that is passed
  1260. * in must exist in the target object. This is regardless whether or not
  1261. * the `have` or `contain` qualifiers are used. Note, either `any` or `all`
  1262. * should be used in the assertion. If neither are used, the assertion is
  1263. * defaulted to `all`.
  1264. *
  1265. * When both `all` and `contain` are used, the target object must have at
  1266. * least all of the passed-in keys but may have more keys not listed.
  1267. *
  1268. * When both `all` and `have` are used, the target object must both contain
  1269. * all of the passed-in keys AND the number of keys in the target object must
  1270. * match the number of keys passed in (in other words, a target object must
  1271. * have all and only all of the passed-in keys).
  1272. *
  1273. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
  1274. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
  1275. * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
  1276. * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
  1277. * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
  1278. * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
  1279. * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});
  1280. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
  1281. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys({'bar': 6});
  1282. *
  1283. *
  1284. * @name keys
  1285. * @alias key
  1286. * @param {...String|Array|Object} keys
  1287. * @namespace BDD
  1288. * @api public
  1289. */
  1290. function assertKeys (keys) {
  1291. var obj = flag(this, 'object')
  1292. , str
  1293. , ok = true
  1294. , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';
  1295. switch (_.type(keys)) {
  1296. case "array":
  1297. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  1298. break;
  1299. case "object":
  1300. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  1301. keys = Object.keys(keys);
  1302. break;
  1303. default:
  1304. keys = Array.prototype.slice.call(arguments);
  1305. }
  1306. if (!keys.length) throw new Error('keys required');
  1307. var actual = Object.keys(obj)
  1308. , expected = keys
  1309. , len = keys.length
  1310. , any = flag(this, 'any')
  1311. , all = flag(this, 'all');
  1312. if (!any && !all) {
  1313. all = true;
  1314. }
  1315. // Has any
  1316. if (any) {
  1317. var intersection = expected.filter(function(key) {
  1318. return ~actual.indexOf(key);
  1319. });
  1320. ok = intersection.length > 0;
  1321. }
  1322. // Has all
  1323. if (all) {
  1324. ok = keys.every(function(key){
  1325. return ~actual.indexOf(key);
  1326. });
  1327. if (!flag(this, 'negate') && !flag(this, 'contains')) {
  1328. ok = ok && keys.length == actual.length;
  1329. }
  1330. }
  1331. // Key string
  1332. if (len > 1) {
  1333. keys = keys.map(function(key){
  1334. return _.inspect(key);
  1335. });
  1336. var last = keys.pop();
  1337. if (all) {
  1338. str = keys.join(', ') + ', and ' + last;
  1339. }
  1340. if (any) {
  1341. str = keys.join(', ') + ', or ' + last;
  1342. }
  1343. } else {
  1344. str = _.inspect(keys[0]);
  1345. }
  1346. // Form
  1347. str = (len > 1 ? 'keys ' : 'key ') + str;
  1348. // Have / include
  1349. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  1350. // Assertion
  1351. this.assert(
  1352. ok
  1353. , 'expected #{this} to ' + str
  1354. , 'expected #{this} to not ' + str
  1355. , expected.slice(0).sort()
  1356. , actual.sort()
  1357. , true
  1358. );
  1359. }
  1360. Assertion.addMethod('keys', assertKeys);
  1361. Assertion.addMethod('key', assertKeys);
  1362. /**
  1363. * ### .throw(constructor)
  1364. *
  1365. * Asserts that the function target will throw a specific error, or specific type of error
  1366. * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
  1367. * for the error's message.
  1368. *
  1369. * var err = new ReferenceError('This is a bad function.');
  1370. * var fn = function () { throw err; }
  1371. * expect(fn).to.throw(ReferenceError);
  1372. * expect(fn).to.throw(Error);
  1373. * expect(fn).to.throw(/bad function/);
  1374. * expect(fn).to.not.throw('good function');
  1375. * expect(fn).to.throw(ReferenceError, /bad function/);
  1376. * expect(fn).to.throw(err);
  1377. *
  1378. * Please note that when a throw expectation is negated, it will check each
  1379. * parameter independently, starting with error constructor type. The appropriate way
  1380. * to check for the existence of a type of error but for a message that does not match
  1381. * is to use `and`.
  1382. *
  1383. * expect(fn).to.throw(ReferenceError)
  1384. * .and.not.throw(/good function/);
  1385. *
  1386. * @name throw
  1387. * @alias throws
  1388. * @alias Throw
  1389. * @param {ErrorConstructor} constructor
  1390. * @param {String|RegExp} expected error message
  1391. * @param {String} message _optional_
  1392. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  1393. * @returns error for chaining (null if no error)
  1394. * @namespace BDD
  1395. * @api public
  1396. */
  1397. function assertThrows (constructor, errMsg, msg) {
  1398. if (msg) flag(this, 'message', msg);
  1399. var obj = flag(this, 'object');
  1400. new Assertion(obj, msg).is.a('function');
  1401. var thrown = false
  1402. , desiredError = null
  1403. , name = null
  1404. , thrownError = null;
  1405. if (arguments.length === 0) {
  1406. errMsg = null;
  1407. constructor = null;
  1408. } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
  1409. errMsg = constructor;
  1410. constructor = null;
  1411. } else if (constructor && constructor instanceof Error) {
  1412. desiredError = constructor;
  1413. constructor = null;
  1414. errMsg = null;
  1415. } else if (typeof constructor === 'function') {
  1416. name = constructor.prototype.name;
  1417. if (!name || (name === 'Error' && constructor !== Error)) {
  1418. name = constructor.name || (new constructor()).name;
  1419. }
  1420. } else {
  1421. constructor = null;
  1422. }
  1423. try {
  1424. obj();
  1425. } catch (err) {
  1426. // first, check desired error
  1427. if (desiredError) {
  1428. this.assert(
  1429. err === desiredError
  1430. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1431. , 'expected #{this} to not throw #{exp}'
  1432. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  1433. , (err instanceof Error ? err.toString() : err)
  1434. );
  1435. flag(this, 'object', err);
  1436. return this;
  1437. }
  1438. // next, check constructor
  1439. if (constructor) {
  1440. this.assert(
  1441. err instanceof constructor
  1442. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1443. , 'expected #{this} to not throw #{exp} but #{act} was thrown'
  1444. , name
  1445. , (err instanceof Error ? err.toString() : err)
  1446. );
  1447. if (!errMsg) {
  1448. flag(this, 'object', err);
  1449. return this;
  1450. }
  1451. }
  1452. // next, check message
  1453. var message = 'error' === _.type(err) && "message" in err
  1454. ? err.message
  1455. : '' + err;
  1456. if ((message != null) && errMsg && errMsg instanceof RegExp) {
  1457. this.assert(
  1458. errMsg.exec(message)
  1459. , 'expected #{this} to throw error matching #{exp} but got #{act}'
  1460. , 'expected #{this} to throw error not matching #{exp}'
  1461. , errMsg
  1462. , message
  1463. );
  1464. flag(this, 'object', err);
  1465. return this;
  1466. } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
  1467. this.assert(
  1468. ~message.indexOf(errMsg)
  1469. , 'expected #{this} to throw error including #{exp} but got #{act}'
  1470. , 'expected #{this} to throw error not including #{act}'
  1471. , errMsg
  1472. , message
  1473. );
  1474. flag(this, 'object', err);
  1475. return this;
  1476. } else {
  1477. thrown = true;
  1478. thrownError = err;
  1479. }
  1480. }
  1481. var actuallyGot = ''
  1482. , expectedThrown = name !== null
  1483. ? name
  1484. : desiredError
  1485. ? '#{exp}' //_.inspect(desiredError)
  1486. : 'an error';
  1487. if (thrown) {
  1488. actuallyGot = ' but #{act} was thrown'
  1489. }
  1490. this.assert(
  1491. thrown === true
  1492. , 'expected #{this} to throw ' + expectedThrown + actuallyGot
  1493. , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
  1494. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  1495. , (thrownError instanceof Error ? thrownError.toString() : thrownError)
  1496. );
  1497. flag(this, 'object', thrownError);
  1498. };
  1499. Assertion.addMethod('throw', assertThrows);
  1500. Assertion.addMethod('throws', assertThrows);
  1501. Assertion.addMethod('Throw', assertThrows);
  1502. /**
  1503. * ### .respondTo(method)
  1504. *
  1505. * Asserts that the object or class target will respond to a method.
  1506. *
  1507. * Klass.prototype.bar = function(){};
  1508. * expect(Klass).to.respondTo('bar');
  1509. * expect(obj).to.respondTo('bar');
  1510. *
  1511. * To check if a constructor will respond to a static function,
  1512. * set the `itself` flag.
  1513. *
  1514. * Klass.baz = function(){};
  1515. * expect(Klass).itself.to.respondTo('baz');
  1516. *
  1517. * @name respondTo
  1518. * @alias respondsTo
  1519. * @param {String} method
  1520. * @param {String} message _optional_
  1521. * @namespace BDD
  1522. * @api public
  1523. */
  1524. function respondTo (method, msg) {
  1525. if (msg) flag(this, 'message', msg);
  1526. var obj = flag(this, 'object')
  1527. , itself = flag(this, 'itself')
  1528. , context = ('function' === _.type(obj) && !itself)
  1529. ? obj.prototype[method]
  1530. : obj[method];
  1531. this.assert(
  1532. 'function' === typeof context
  1533. , 'expected #{this} to respond to ' + _.inspect(method)
  1534. , 'expected #{this} to not respond to ' + _.inspect(method)
  1535. );
  1536. }
  1537. Assertion.addMethod('respondTo', respondTo);
  1538. Assertion.addMethod('respondsTo', respondTo);
  1539. /**
  1540. * ### .itself
  1541. *
  1542. * Sets the `itself` flag, later used by the `respondTo` assertion.
  1543. *
  1544. * function Foo() {}
  1545. * Foo.bar = function() {}
  1546. * Foo.prototype.baz = function() {}
  1547. *
  1548. * expect(Foo).itself.to.respondTo('bar');
  1549. * expect(Foo).itself.not.to.respondTo('baz');
  1550. *
  1551. * @name itself
  1552. * @namespace BDD
  1553. * @api public
  1554. */
  1555. Assertion.addProperty('itself', function () {
  1556. flag(this, 'itself', true);
  1557. });
  1558. /**
  1559. * ### .satisfy(method)
  1560. *
  1561. * Asserts that the target passes a given truth test.
  1562. *
  1563. * expect(1).to.satisfy(function(num) { return num > 0; });
  1564. *
  1565. * @name satisfy
  1566. * @alias satisfies
  1567. * @param {Function} matcher
  1568. * @param {String} message _optional_
  1569. * @namespace BDD
  1570. * @api public
  1571. */
  1572. function satisfy (matcher, msg) {
  1573. if (msg) flag(this, 'message', msg);
  1574. var obj = flag(this, 'object');
  1575. var result = matcher(obj);
  1576. this.assert(
  1577. result
  1578. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  1579. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  1580. , this.negate ? false : true
  1581. , result
  1582. );
  1583. }
  1584. Assertion.addMethod('satisfy', satisfy);
  1585. Assertion.addMethod('satisfies', satisfy);
  1586. /**
  1587. * ### .closeTo(expected, delta)
  1588. *
  1589. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  1590. *
  1591. * expect(1.5).to.be.closeTo(1, 0.5);
  1592. *
  1593. * @name closeTo
  1594. * @alias approximately
  1595. * @param {Number} expected
  1596. * @param {Number} delta
  1597. * @param {String} message _optional_
  1598. * @namespace BDD
  1599. * @api public
  1600. */
  1601. function closeTo(expected, delta, msg) {
  1602. if (msg) flag(this, 'message', msg);
  1603. var obj = flag(this, 'object');
  1604. new Assertion(obj, msg).is.a('number');
  1605. if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
  1606. throw new Error('the arguments to closeTo or approximately must be numbers');
  1607. }
  1608. this.assert(
  1609. Math.abs(obj - expected) <= delta
  1610. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  1611. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  1612. );
  1613. }
  1614. Assertion.addMethod('closeTo', closeTo);
  1615. Assertion.addMethod('approximately', closeTo);
  1616. function isSubsetOf(subset, superset, cmp) {
  1617. return subset.every(function(elem) {
  1618. if (!cmp) return superset.indexOf(elem) !== -1;
  1619. return superset.some(function(elem2) {
  1620. return cmp(elem, elem2);
  1621. });
  1622. })
  1623. }
  1624. /**
  1625. * ### .members(set)
  1626. *
  1627. * Asserts that the target is a superset of `set`,
  1628. * or that the target and `set` have the same strictly-equal (===) members.
  1629. * Alternately, if the `deep` flag is set, set members are compared for deep
  1630. * equality.
  1631. *
  1632. * expect([1, 2, 3]).to.include.members([3, 2]);
  1633. * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
  1634. *
  1635. * expect([4, 2]).to.have.members([2, 4]);
  1636. * expect([5, 2]).to.not.have.members([5, 2, 1]);
  1637. *
  1638. * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
  1639. *
  1640. * @name members
  1641. * @param {Array} set
  1642. * @param {String} message _optional_
  1643. * @namespace BDD
  1644. * @api public
  1645. */
  1646. Assertion.addMethod('members', function (subset, msg) {
  1647. if (msg) flag(this, 'message', msg);
  1648. var obj = flag(this, 'object');
  1649. new Assertion(obj).to.be.an('array');
  1650. new Assertion(subset).to.be.an('array');
  1651. var cmp = flag(this, 'deep') ? _.eql : undefined;
  1652. if (flag(this, 'contains')) {
  1653. return this.assert(
  1654. isSubsetOf(subset, obj, cmp)
  1655. , 'expected #{this} to be a superset of #{act}'
  1656. , 'expected #{this} to not be a superset of #{act}'
  1657. , obj
  1658. , subset
  1659. );
  1660. }
  1661. this.assert(
  1662. isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
  1663. , 'expected #{this} to have the same members as #{act}'
  1664. , 'expected #{this} to not have the same members as #{act}'
  1665. , obj
  1666. , subset
  1667. );
  1668. });
  1669. /**
  1670. * ### .oneOf(list)
  1671. *
  1672. * Assert that a value appears somewhere in the top level of array `list`.
  1673. *
  1674. * expect('a').to.be.oneOf(['a', 'b', 'c']);
  1675. * expect(9).to.not.be.oneOf(['z']);
  1676. * expect([3]).to.not.be.oneOf([1, 2, [3]]);
  1677. *
  1678. * var three = [3];
  1679. * // for object-types, contents are not compared
  1680. * expect(three).to.not.be.oneOf([1, 2, [3]]);
  1681. * // comparing references works
  1682. * expect(three).to.be.oneOf([1, 2, three]);
  1683. *
  1684. * @name oneOf
  1685. * @param {Array<*>} list
  1686. * @param {String} message _optional_
  1687. * @namespace BDD
  1688. * @api public
  1689. */
  1690. function oneOf (list, msg) {
  1691. if (msg) flag(this, 'message', msg);
  1692. var expected = flag(this, 'object');
  1693. new Assertion(list).to.be.an('array');
  1694. this.assert(
  1695. list.indexOf(expected) > -1
  1696. , 'expected #{this} to be one of #{exp}'
  1697. , 'expected #{this} to not be one of #{exp}'
  1698. , list
  1699. , expected
  1700. );
  1701. }
  1702. Assertion.addMethod('oneOf', oneOf);
  1703. /**
  1704. * ### .change(function)
  1705. *
  1706. * Asserts that a function changes an object property
  1707. *
  1708. * var obj = { val: 10 };
  1709. * var fn = function() { obj.val += 3 };
  1710. * var noChangeFn = function() { return 'foo' + 'bar'; }
  1711. * expect(fn).to.change(obj, 'val');
  1712. * expect(noChangeFn).to.not.change(obj, 'val')
  1713. *
  1714. * @name change
  1715. * @alias changes
  1716. * @alias Change
  1717. * @param {String} object
  1718. * @param {String} property name
  1719. * @param {String} message _optional_
  1720. * @namespace BDD
  1721. * @api public
  1722. */
  1723. function assertChanges (object, prop, msg) {
  1724. if (msg) flag(this, 'message', msg);
  1725. var fn = flag(this, 'object');
  1726. new Assertion(object, msg).to.have.property(prop);
  1727. new Assertion(fn).is.a('function');
  1728. var initial = object[prop];
  1729. fn();
  1730. this.assert(
  1731. initial !== object[prop]
  1732. , 'expected .' + prop + ' to change'
  1733. , 'expected .' + prop + ' to not change'
  1734. );
  1735. }
  1736. Assertion.addChainableMethod('change', assertChanges);
  1737. Assertion.addChainableMethod('changes', assertChanges);
  1738. /**
  1739. * ### .increase(function)
  1740. *
  1741. * Asserts that a function increases an object property
  1742. *
  1743. * var obj = { val: 10 };
  1744. * var fn = function() { obj.val = 15 };
  1745. * expect(fn).to.increase(obj, 'val');
  1746. *
  1747. * @name increase
  1748. * @alias increases
  1749. * @alias Increase
  1750. * @param {String} object
  1751. * @param {String} property name
  1752. * @param {String} message _optional_
  1753. * @namespace BDD
  1754. * @api public
  1755. */
  1756. function assertIncreases (object, prop, msg) {
  1757. if (msg) flag(this, 'message', msg);
  1758. var fn = flag(this, 'object');
  1759. new Assertion(object, msg).to.have.property(prop);
  1760. new Assertion(fn).is.a('function');
  1761. var initial = object[prop];
  1762. fn();
  1763. this.assert(
  1764. object[prop] - initial > 0
  1765. , 'expected .' + prop + ' to increase'
  1766. , 'expected .' + prop + ' to not increase'
  1767. );
  1768. }
  1769. Assertion.addChainableMethod('increase', assertIncreases);
  1770. Assertion.addChainableMethod('increases', assertIncreases);
  1771. /**
  1772. * ### .decrease(function)
  1773. *
  1774. * Asserts that a function decreases an object property
  1775. *
  1776. * var obj = { val: 10 };
  1777. * var fn = function() { obj.val = 5 };
  1778. * expect(fn).to.decrease(obj, 'val');
  1779. *
  1780. * @name decrease
  1781. * @alias decreases
  1782. * @alias Decrease
  1783. * @param {String} object
  1784. * @param {String} property name
  1785. * @param {String} message _optional_
  1786. * @namespace BDD
  1787. * @api public
  1788. */
  1789. function assertDecreases (object, prop, msg) {
  1790. if (msg) flag(this, 'message', msg);
  1791. var fn = flag(this, 'object');
  1792. new Assertion(object, msg).to.have.property(prop);
  1793. new Assertion(fn).is.a('function');
  1794. var initial = object[prop];
  1795. fn();
  1796. this.assert(
  1797. object[prop] - initial < 0
  1798. , 'expected .' + prop + ' to decrease'
  1799. , 'expected .' + prop + ' to not decrease'
  1800. );
  1801. }
  1802. Assertion.addChainableMethod('decrease', assertDecreases);
  1803. Assertion.addChainableMethod('decreases', assertDecreases);
  1804. /**
  1805. * ### .extensible
  1806. *
  1807. * Asserts that the target is extensible (can have new properties added to
  1808. * it).
  1809. *
  1810. * var nonExtensibleObject = Object.preventExtensions({});
  1811. * var sealedObject = Object.seal({});
  1812. * var frozenObject = Object.freeze({});
  1813. *
  1814. * expect({}).to.be.extensible;
  1815. * expect(nonExtensibleObject).to.not.be.extensible;
  1816. * expect(sealedObject).to.not.be.extensible;
  1817. * expect(frozenObject).to.not.be.extensible;
  1818. *
  1819. * @name extensible
  1820. * @namespace BDD
  1821. * @api public
  1822. */
  1823. Assertion.addProperty('extensible', function() {
  1824. var obj = flag(this, 'object');
  1825. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  1826. // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
  1827. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
  1828. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  1829. var isExtensible;
  1830. try {
  1831. isExtensible = Object.isExtensible(obj);
  1832. } catch (err) {
  1833. if (err instanceof TypeError) isExtensible = false;
  1834. else throw err;
  1835. }
  1836. this.assert(
  1837. isExtensible
  1838. , 'expected #{this} to be extensible'
  1839. , 'expected #{this} to not be extensible'
  1840. );
  1841. });
  1842. /**
  1843. * ### .sealed
  1844. *
  1845. * Asserts that the target is sealed (cannot have new properties added to it
  1846. * and its existing properties cannot be removed).
  1847. *
  1848. * var sealedObject = Object.seal({});
  1849. * var frozenObject = Object.freeze({});
  1850. *
  1851. * expect(sealedObject).to.be.sealed;
  1852. * expect(frozenObject).to.be.sealed;
  1853. * expect({}).to.not.be.sealed;
  1854. *
  1855. * @name sealed
  1856. * @namespace BDD
  1857. * @api public
  1858. */
  1859. Assertion.addProperty('sealed', function() {
  1860. var obj = flag(this, 'object');
  1861. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  1862. // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
  1863. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
  1864. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  1865. var isSealed;
  1866. try {
  1867. isSealed = Object.isSealed(obj);
  1868. } catch (err) {
  1869. if (err instanceof TypeError) isSealed = true;
  1870. else throw err;
  1871. }
  1872. this.assert(
  1873. isSealed
  1874. , 'expected #{this} to be sealed'
  1875. , 'expected #{this} to not be sealed'
  1876. );
  1877. });
  1878. /**
  1879. * ### .frozen
  1880. *
  1881. * Asserts that the target is frozen (cannot have new properties added to it
  1882. * and its existing properties cannot be modified).
  1883. *
  1884. * var frozenObject = Object.freeze({});
  1885. *
  1886. * expect(frozenObject).to.be.frozen;
  1887. * expect({}).to.not.be.frozen;
  1888. *
  1889. * @name frozen
  1890. * @namespace BDD
  1891. * @api public
  1892. */
  1893. Assertion.addProperty('frozen', function() {
  1894. var obj = flag(this, 'object');
  1895. // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
  1896. // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
  1897. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
  1898. // The following provides ES6 behavior when a TypeError is thrown under ES5.
  1899. var isFrozen;
  1900. try {
  1901. isFrozen = Object.isFrozen(obj);
  1902. } catch (err) {
  1903. if (err instanceof TypeError) isFrozen = true;
  1904. else throw err;
  1905. }
  1906. this.assert(
  1907. isFrozen
  1908. , 'expected #{this} to be frozen'
  1909. , 'expected #{this} to not be frozen'
  1910. );
  1911. });
  1912. };
  1913. },{}],6:[function(require,module,exports){
  1914. /*!
  1915. * chai
  1916. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  1917. * MIT Licensed
  1918. */
  1919. module.exports = function (chai, util) {
  1920. /*!
  1921. * Chai dependencies.
  1922. */
  1923. var Assertion = chai.Assertion
  1924. , flag = util.flag;
  1925. /*!
  1926. * Module export.
  1927. */
  1928. /**
  1929. * ### assert(expression, message)
  1930. *
  1931. * Write your own test expressions.
  1932. *
  1933. * assert('foo' !== 'bar', 'foo is not bar');
  1934. * assert(Array.isArray([]), 'empty arrays are arrays');
  1935. *
  1936. * @param {Mixed} expression to test for truthiness
  1937. * @param {String} message to display on error
  1938. * @name assert
  1939. * @namespace Assert
  1940. * @api public
  1941. */
  1942. var assert = chai.assert = function (express, errmsg) {
  1943. var test = new Assertion(null, null, chai.assert);
  1944. test.assert(
  1945. express
  1946. , errmsg
  1947. , '[ negation message unavailable ]'
  1948. );
  1949. };
  1950. /**
  1951. * ### .fail(actual, expected, [message], [operator])
  1952. *
  1953. * Throw a failure. Node.js `assert` module-compatible.
  1954. *
  1955. * @name fail
  1956. * @param {Mixed} actual
  1957. * @param {Mixed} expected
  1958. * @param {String} message
  1959. * @param {String} operator
  1960. * @namespace Assert
  1961. * @api public
  1962. */
  1963. assert.fail = function (actual, expected, message, operator) {
  1964. message = message || 'assert.fail()';
  1965. throw new chai.AssertionError(message, {
  1966. actual: actual
  1967. , expected: expected
  1968. , operator: operator
  1969. }, assert.fail);
  1970. };
  1971. /**
  1972. * ### .isOk(object, [message])
  1973. *
  1974. * Asserts that `object` is truthy.
  1975. *
  1976. * assert.isOk('everything', 'everything is ok');
  1977. * assert.isOk(false, 'this will fail');
  1978. *
  1979. * @name isOk
  1980. * @alias ok
  1981. * @param {Mixed} object to test
  1982. * @param {String} message
  1983. * @namespace Assert
  1984. * @api public
  1985. */
  1986. assert.isOk = function (val, msg) {
  1987. new Assertion(val, msg).is.ok;
  1988. };
  1989. /**
  1990. * ### .isNotOk(object, [message])
  1991. *
  1992. * Asserts that `object` is falsy.
  1993. *
  1994. * assert.isNotOk('everything', 'this will fail');
  1995. * assert.isNotOk(false, 'this will pass');
  1996. *
  1997. * @name isNotOk
  1998. * @alias notOk
  1999. * @param {Mixed} object to test
  2000. * @param {String} message
  2001. * @namespace Assert
  2002. * @api public
  2003. */
  2004. assert.isNotOk = function (val, msg) {
  2005. new Assertion(val, msg).is.not.ok;
  2006. };
  2007. /**
  2008. * ### .equal(actual, expected, [message])
  2009. *
  2010. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  2011. *
  2012. * assert.equal(3, '3', '== coerces values to strings');
  2013. *
  2014. * @name equal
  2015. * @param {Mixed} actual
  2016. * @param {Mixed} expected
  2017. * @param {String} message
  2018. * @namespace Assert
  2019. * @api public
  2020. */
  2021. assert.equal = function (act, exp, msg) {
  2022. var test = new Assertion(act, msg, assert.equal);
  2023. test.assert(
  2024. exp == flag(test, 'object')
  2025. , 'expected #{this} to equal #{exp}'
  2026. , 'expected #{this} to not equal #{act}'
  2027. , exp
  2028. , act
  2029. );
  2030. };
  2031. /**
  2032. * ### .notEqual(actual, expected, [message])
  2033. *
  2034. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  2035. *
  2036. * assert.notEqual(3, 4, 'these numbers are not equal');
  2037. *
  2038. * @name notEqual
  2039. * @param {Mixed} actual
  2040. * @param {Mixed} expected
  2041. * @param {String} message
  2042. * @namespace Assert
  2043. * @api public
  2044. */
  2045. assert.notEqual = function (act, exp, msg) {
  2046. var test = new Assertion(act, msg, assert.notEqual);
  2047. test.assert(
  2048. exp != flag(test, 'object')
  2049. , 'expected #{this} to not equal #{exp}'
  2050. , 'expected #{this} to equal #{act}'
  2051. , exp
  2052. , act
  2053. );
  2054. };
  2055. /**
  2056. * ### .strictEqual(actual, expected, [message])
  2057. *
  2058. * Asserts strict equality (`===`) of `actual` and `expected`.
  2059. *
  2060. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  2061. *
  2062. * @name strictEqual
  2063. * @param {Mixed} actual
  2064. * @param {Mixed} expected
  2065. * @param {String} message
  2066. * @namespace Assert
  2067. * @api public
  2068. */
  2069. assert.strictEqual = function (act, exp, msg) {
  2070. new Assertion(act, msg).to.equal(exp);
  2071. };
  2072. /**
  2073. * ### .notStrictEqual(actual, expected, [message])
  2074. *
  2075. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  2076. *
  2077. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  2078. *
  2079. * @name notStrictEqual
  2080. * @param {Mixed} actual
  2081. * @param {Mixed} expected
  2082. * @param {String} message
  2083. * @namespace Assert
  2084. * @api public
  2085. */
  2086. assert.notStrictEqual = function (act, exp, msg) {
  2087. new Assertion(act, msg).to.not.equal(exp);
  2088. };
  2089. /**
  2090. * ### .deepEqual(actual, expected, [message])
  2091. *
  2092. * Asserts that `actual` is deeply equal to `expected`.
  2093. *
  2094. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  2095. *
  2096. * @name deepEqual
  2097. * @param {Mixed} actual
  2098. * @param {Mixed} expected
  2099. * @param {String} message
  2100. * @namespace Assert
  2101. * @api public
  2102. */
  2103. assert.deepEqual = function (act, exp, msg) {
  2104. new Assertion(act, msg).to.eql(exp);
  2105. };
  2106. /**
  2107. * ### .notDeepEqual(actual, expected, [message])
  2108. *
  2109. * Assert that `actual` is not deeply equal to `expected`.
  2110. *
  2111. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  2112. *
  2113. * @name notDeepEqual
  2114. * @param {Mixed} actual
  2115. * @param {Mixed} expected
  2116. * @param {String} message
  2117. * @namespace Assert
  2118. * @api public
  2119. */
  2120. assert.notDeepEqual = function (act, exp, msg) {
  2121. new Assertion(act, msg).to.not.eql(exp);
  2122. };
  2123. /**
  2124. * ### .isAbove(valueToCheck, valueToBeAbove, [message])
  2125. *
  2126. * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
  2127. *
  2128. * assert.isAbove(5, 2, '5 is strictly greater than 2');
  2129. *
  2130. * @name isAbove
  2131. * @param {Mixed} valueToCheck
  2132. * @param {Mixed} valueToBeAbove
  2133. * @param {String} message
  2134. * @namespace Assert
  2135. * @api public
  2136. */
  2137. assert.isAbove = function (val, abv, msg) {
  2138. new Assertion(val, msg).to.be.above(abv);
  2139. };
  2140. /**
  2141. * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
  2142. *
  2143. * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`
  2144. *
  2145. * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
  2146. * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
  2147. *
  2148. * @name isAtLeast
  2149. * @param {Mixed} valueToCheck
  2150. * @param {Mixed} valueToBeAtLeast
  2151. * @param {String} message
  2152. * @namespace Assert
  2153. * @api public
  2154. */
  2155. assert.isAtLeast = function (val, atlst, msg) {
  2156. new Assertion(val, msg).to.be.least(atlst);
  2157. };
  2158. /**
  2159. * ### .isBelow(valueToCheck, valueToBeBelow, [message])
  2160. *
  2161. * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`
  2162. *
  2163. * assert.isBelow(3, 6, '3 is strictly less than 6');
  2164. *
  2165. * @name isBelow
  2166. * @param {Mixed} valueToCheck
  2167. * @param {Mixed} valueToBeBelow
  2168. * @param {String} message
  2169. * @namespace Assert
  2170. * @api public
  2171. */
  2172. assert.isBelow = function (val, blw, msg) {
  2173. new Assertion(val, msg).to.be.below(blw);
  2174. };
  2175. /**
  2176. * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
  2177. *
  2178. * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
  2179. *
  2180. * assert.isAtMost(3, 6, '3 is less than or equal to 6');
  2181. * assert.isAtMost(4, 4, '4 is less than or equal to 4');
  2182. *
  2183. * @name isAtMost
  2184. * @param {Mixed} valueToCheck
  2185. * @param {Mixed} valueToBeAtMost
  2186. * @param {String} message
  2187. * @namespace Assert
  2188. * @api public
  2189. */
  2190. assert.isAtMost = function (val, atmst, msg) {
  2191. new Assertion(val, msg).to.be.most(atmst);
  2192. };
  2193. /**
  2194. * ### .isTrue(value, [message])
  2195. *
  2196. * Asserts that `value` is true.
  2197. *
  2198. * var teaServed = true;
  2199. * assert.isTrue(teaServed, 'the tea has been served');
  2200. *
  2201. * @name isTrue
  2202. * @param {Mixed} value
  2203. * @param {String} message
  2204. * @namespace Assert
  2205. * @api public
  2206. */
  2207. assert.isTrue = function (val, msg) {
  2208. new Assertion(val, msg).is['true'];
  2209. };
  2210. /**
  2211. * ### .isNotTrue(value, [message])
  2212. *
  2213. * Asserts that `value` is not true.
  2214. *
  2215. * var tea = 'tasty chai';
  2216. * assert.isNotTrue(tea, 'great, time for tea!');
  2217. *
  2218. * @name isNotTrue
  2219. * @param {Mixed} value
  2220. * @param {String} message
  2221. * @namespace Assert
  2222. * @api public
  2223. */
  2224. assert.isNotTrue = function (val, msg) {
  2225. new Assertion(val, msg).to.not.equal(true);
  2226. };
  2227. /**
  2228. * ### .isFalse(value, [message])
  2229. *
  2230. * Asserts that `value` is false.
  2231. *
  2232. * var teaServed = false;
  2233. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  2234. *
  2235. * @name isFalse
  2236. * @param {Mixed} value
  2237. * @param {String} message
  2238. * @namespace Assert
  2239. * @api public
  2240. */
  2241. assert.isFalse = function (val, msg) {
  2242. new Assertion(val, msg).is['false'];
  2243. };
  2244. /**
  2245. * ### .isNotFalse(value, [message])
  2246. *
  2247. * Asserts that `value` is not false.
  2248. *
  2249. * var tea = 'tasty chai';
  2250. * assert.isNotFalse(tea, 'great, time for tea!');
  2251. *
  2252. * @name isNotFalse
  2253. * @param {Mixed} value
  2254. * @param {String} message
  2255. * @namespace Assert
  2256. * @api public
  2257. */
  2258. assert.isNotFalse = function (val, msg) {
  2259. new Assertion(val, msg).to.not.equal(false);
  2260. };
  2261. /**
  2262. * ### .isNull(value, [message])
  2263. *
  2264. * Asserts that `value` is null.
  2265. *
  2266. * assert.isNull(err, 'there was no error');
  2267. *
  2268. * @name isNull
  2269. * @param {Mixed} value
  2270. * @param {String} message
  2271. * @namespace Assert
  2272. * @api public
  2273. */
  2274. assert.isNull = function (val, msg) {
  2275. new Assertion(val, msg).to.equal(null);
  2276. };
  2277. /**
  2278. * ### .isNotNull(value, [message])
  2279. *
  2280. * Asserts that `value` is not null.
  2281. *
  2282. * var tea = 'tasty chai';
  2283. * assert.isNotNull(tea, 'great, time for tea!');
  2284. *
  2285. * @name isNotNull
  2286. * @param {Mixed} value
  2287. * @param {String} message
  2288. * @namespace Assert
  2289. * @api public
  2290. */
  2291. assert.isNotNull = function (val, msg) {
  2292. new Assertion(val, msg).to.not.equal(null);
  2293. };
  2294. /**
  2295. * ### .isNaN
  2296. * Asserts that value is NaN
  2297. *
  2298. * assert.isNaN('foo', 'foo is NaN');
  2299. *
  2300. * @name isNaN
  2301. * @param {Mixed} value
  2302. * @param {String} message
  2303. * @namespace Assert
  2304. * @api public
  2305. */
  2306. assert.isNaN = function (val, msg) {
  2307. new Assertion(val, msg).to.be.NaN;
  2308. };
  2309. /**
  2310. * ### .isNotNaN
  2311. * Asserts that value is not NaN
  2312. *
  2313. * assert.isNotNaN(4, '4 is not NaN');
  2314. *
  2315. * @name isNotNaN
  2316. * @param {Mixed} value
  2317. * @param {String} message
  2318. * @namespace Assert
  2319. * @api public
  2320. */
  2321. assert.isNotNaN = function (val, msg) {
  2322. new Assertion(val, msg).not.to.be.NaN;
  2323. };
  2324. /**
  2325. * ### .isUndefined(value, [message])
  2326. *
  2327. * Asserts that `value` is `undefined`.
  2328. *
  2329. * var tea;
  2330. * assert.isUndefined(tea, 'no tea defined');
  2331. *
  2332. * @name isUndefined
  2333. * @param {Mixed} value
  2334. * @param {String} message
  2335. * @namespace Assert
  2336. * @api public
  2337. */
  2338. assert.isUndefined = function (val, msg) {
  2339. new Assertion(val, msg).to.equal(undefined);
  2340. };
  2341. /**
  2342. * ### .isDefined(value, [message])
  2343. *
  2344. * Asserts that `value` is not `undefined`.
  2345. *
  2346. * var tea = 'cup of chai';
  2347. * assert.isDefined(tea, 'tea has been defined');
  2348. *
  2349. * @name isDefined
  2350. * @param {Mixed} value
  2351. * @param {String} message
  2352. * @namespace Assert
  2353. * @api public
  2354. */
  2355. assert.isDefined = function (val, msg) {
  2356. new Assertion(val, msg).to.not.equal(undefined);
  2357. };
  2358. /**
  2359. * ### .isFunction(value, [message])
  2360. *
  2361. * Asserts that `value` is a function.
  2362. *
  2363. * function serveTea() { return 'cup of tea'; };
  2364. * assert.isFunction(serveTea, 'great, we can have tea now');
  2365. *
  2366. * @name isFunction
  2367. * @param {Mixed} value
  2368. * @param {String} message
  2369. * @namespace Assert
  2370. * @api public
  2371. */
  2372. assert.isFunction = function (val, msg) {
  2373. new Assertion(val, msg).to.be.a('function');
  2374. };
  2375. /**
  2376. * ### .isNotFunction(value, [message])
  2377. *
  2378. * Asserts that `value` is _not_ a function.
  2379. *
  2380. * var serveTea = [ 'heat', 'pour', 'sip' ];
  2381. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  2382. *
  2383. * @name isNotFunction
  2384. * @param {Mixed} value
  2385. * @param {String} message
  2386. * @namespace Assert
  2387. * @api public
  2388. */
  2389. assert.isNotFunction = function (val, msg) {
  2390. new Assertion(val, msg).to.not.be.a('function');
  2391. };
  2392. /**
  2393. * ### .isObject(value, [message])
  2394. *
  2395. * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
  2396. * _The assertion does not match subclassed objects._
  2397. *
  2398. * var selection = { name: 'Chai', serve: 'with spices' };
  2399. * assert.isObject(selection, 'tea selection is an object');
  2400. *
  2401. * @name isObject
  2402. * @param {Mixed} value
  2403. * @param {String} message
  2404. * @namespace Assert
  2405. * @api public
  2406. */
  2407. assert.isObject = function (val, msg) {
  2408. new Assertion(val, msg).to.be.a('object');
  2409. };
  2410. /**
  2411. * ### .isNotObject(value, [message])
  2412. *
  2413. * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
  2414. *
  2415. * var selection = 'chai'
  2416. * assert.isNotObject(selection, 'tea selection is not an object');
  2417. * assert.isNotObject(null, 'null is not an object');
  2418. *
  2419. * @name isNotObject
  2420. * @param {Mixed} value
  2421. * @param {String} message
  2422. * @namespace Assert
  2423. * @api public
  2424. */
  2425. assert.isNotObject = function (val, msg) {
  2426. new Assertion(val, msg).to.not.be.a('object');
  2427. };
  2428. /**
  2429. * ### .isArray(value, [message])
  2430. *
  2431. * Asserts that `value` is an array.
  2432. *
  2433. * var menu = [ 'green', 'chai', 'oolong' ];
  2434. * assert.isArray(menu, 'what kind of tea do we want?');
  2435. *
  2436. * @name isArray
  2437. * @param {Mixed} value
  2438. * @param {String} message
  2439. * @namespace Assert
  2440. * @api public
  2441. */
  2442. assert.isArray = function (val, msg) {
  2443. new Assertion(val, msg).to.be.an('array');
  2444. };
  2445. /**
  2446. * ### .isNotArray(value, [message])
  2447. *
  2448. * Asserts that `value` is _not_ an array.
  2449. *
  2450. * var menu = 'green|chai|oolong';
  2451. * assert.isNotArray(menu, 'what kind of tea do we want?');
  2452. *
  2453. * @name isNotArray
  2454. * @param {Mixed} value
  2455. * @param {String} message
  2456. * @namespace Assert
  2457. * @api public
  2458. */
  2459. assert.isNotArray = function (val, msg) {
  2460. new Assertion(val, msg).to.not.be.an('array');
  2461. };
  2462. /**
  2463. * ### .isString(value, [message])
  2464. *
  2465. * Asserts that `value` is a string.
  2466. *
  2467. * var teaOrder = 'chai';
  2468. * assert.isString(teaOrder, 'order placed');
  2469. *
  2470. * @name isString
  2471. * @param {Mixed} value
  2472. * @param {String} message
  2473. * @namespace Assert
  2474. * @api public
  2475. */
  2476. assert.isString = function (val, msg) {
  2477. new Assertion(val, msg).to.be.a('string');
  2478. };
  2479. /**
  2480. * ### .isNotString(value, [message])
  2481. *
  2482. * Asserts that `value` is _not_ a string.
  2483. *
  2484. * var teaOrder = 4;
  2485. * assert.isNotString(teaOrder, 'order placed');
  2486. *
  2487. * @name isNotString
  2488. * @param {Mixed} value
  2489. * @param {String} message
  2490. * @namespace Assert
  2491. * @api public
  2492. */
  2493. assert.isNotString = function (val, msg) {
  2494. new Assertion(val, msg).to.not.be.a('string');
  2495. };
  2496. /**
  2497. * ### .isNumber(value, [message])
  2498. *
  2499. * Asserts that `value` is a number.
  2500. *
  2501. * var cups = 2;
  2502. * assert.isNumber(cups, 'how many cups');
  2503. *
  2504. * @name isNumber
  2505. * @param {Number} value
  2506. * @param {String} message
  2507. * @namespace Assert
  2508. * @api public
  2509. */
  2510. assert.isNumber = function (val, msg) {
  2511. new Assertion(val, msg).to.be.a('number');
  2512. };
  2513. /**
  2514. * ### .isNotNumber(value, [message])
  2515. *
  2516. * Asserts that `value` is _not_ a number.
  2517. *
  2518. * var cups = '2 cups please';
  2519. * assert.isNotNumber(cups, 'how many cups');
  2520. *
  2521. * @name isNotNumber
  2522. * @param {Mixed} value
  2523. * @param {String} message
  2524. * @namespace Assert
  2525. * @api public
  2526. */
  2527. assert.isNotNumber = function (val, msg) {
  2528. new Assertion(val, msg).to.not.be.a('number');
  2529. };
  2530. /**
  2531. * ### .isBoolean(value, [message])
  2532. *
  2533. * Asserts that `value` is a boolean.
  2534. *
  2535. * var teaReady = true
  2536. * , teaServed = false;
  2537. *
  2538. * assert.isBoolean(teaReady, 'is the tea ready');
  2539. * assert.isBoolean(teaServed, 'has tea been served');
  2540. *
  2541. * @name isBoolean
  2542. * @param {Mixed} value
  2543. * @param {String} message
  2544. * @namespace Assert
  2545. * @api public
  2546. */
  2547. assert.isBoolean = function (val, msg) {
  2548. new Assertion(val, msg).to.be.a('boolean');
  2549. };
  2550. /**
  2551. * ### .isNotBoolean(value, [message])
  2552. *
  2553. * Asserts that `value` is _not_ a boolean.
  2554. *
  2555. * var teaReady = 'yep'
  2556. * , teaServed = 'nope';
  2557. *
  2558. * assert.isNotBoolean(teaReady, 'is the tea ready');
  2559. * assert.isNotBoolean(teaServed, 'has tea been served');
  2560. *
  2561. * @name isNotBoolean
  2562. * @param {Mixed} value
  2563. * @param {String} message
  2564. * @namespace Assert
  2565. * @api public
  2566. */
  2567. assert.isNotBoolean = function (val, msg) {
  2568. new Assertion(val, msg).to.not.be.a('boolean');
  2569. };
  2570. /**
  2571. * ### .typeOf(value, name, [message])
  2572. *
  2573. * Asserts that `value`'s type is `name`, as determined by
  2574. * `Object.prototype.toString`.
  2575. *
  2576. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  2577. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  2578. * assert.typeOf('tea', 'string', 'we have a string');
  2579. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  2580. * assert.typeOf(null, 'null', 'we have a null');
  2581. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  2582. *
  2583. * @name typeOf
  2584. * @param {Mixed} value
  2585. * @param {String} name
  2586. * @param {String} message
  2587. * @namespace Assert
  2588. * @api public
  2589. */
  2590. assert.typeOf = function (val, type, msg) {
  2591. new Assertion(val, msg).to.be.a(type);
  2592. };
  2593. /**
  2594. * ### .notTypeOf(value, name, [message])
  2595. *
  2596. * Asserts that `value`'s type is _not_ `name`, as determined by
  2597. * `Object.prototype.toString`.
  2598. *
  2599. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  2600. *
  2601. * @name notTypeOf
  2602. * @param {Mixed} value
  2603. * @param {String} typeof name
  2604. * @param {String} message
  2605. * @namespace Assert
  2606. * @api public
  2607. */
  2608. assert.notTypeOf = function (val, type, msg) {
  2609. new Assertion(val, msg).to.not.be.a(type);
  2610. };
  2611. /**
  2612. * ### .instanceOf(object, constructor, [message])
  2613. *
  2614. * Asserts that `value` is an instance of `constructor`.
  2615. *
  2616. * var Tea = function (name) { this.name = name; }
  2617. * , chai = new Tea('chai');
  2618. *
  2619. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  2620. *
  2621. * @name instanceOf
  2622. * @param {Object} object
  2623. * @param {Constructor} constructor
  2624. * @param {String} message
  2625. * @namespace Assert
  2626. * @api public
  2627. */
  2628. assert.instanceOf = function (val, type, msg) {
  2629. new Assertion(val, msg).to.be.instanceOf(type);
  2630. };
  2631. /**
  2632. * ### .notInstanceOf(object, constructor, [message])
  2633. *
  2634. * Asserts `value` is not an instance of `constructor`.
  2635. *
  2636. * var Tea = function (name) { this.name = name; }
  2637. * , chai = new String('chai');
  2638. *
  2639. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  2640. *
  2641. * @name notInstanceOf
  2642. * @param {Object} object
  2643. * @param {Constructor} constructor
  2644. * @param {String} message
  2645. * @namespace Assert
  2646. * @api public
  2647. */
  2648. assert.notInstanceOf = function (val, type, msg) {
  2649. new Assertion(val, msg).to.not.be.instanceOf(type);
  2650. };
  2651. /**
  2652. * ### .include(haystack, needle, [message])
  2653. *
  2654. * Asserts that `haystack` includes `needle`. Works
  2655. * for strings and arrays.
  2656. *
  2657. * assert.include('foobar', 'bar', 'foobar contains string "bar"');
  2658. * assert.include([ 1, 2, 3 ], 3, 'array contains value');
  2659. *
  2660. * @name include
  2661. * @param {Array|String} haystack
  2662. * @param {Mixed} needle
  2663. * @param {String} message
  2664. * @namespace Assert
  2665. * @api public
  2666. */
  2667. assert.include = function (exp, inc, msg) {
  2668. new Assertion(exp, msg, assert.include).include(inc);
  2669. };
  2670. /**
  2671. * ### .notInclude(haystack, needle, [message])
  2672. *
  2673. * Asserts that `haystack` does not include `needle`. Works
  2674. * for strings and arrays.
  2675. *
  2676. * assert.notInclude('foobar', 'baz', 'string not include substring');
  2677. * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
  2678. *
  2679. * @name notInclude
  2680. * @param {Array|String} haystack
  2681. * @param {Mixed} needle
  2682. * @param {String} message
  2683. * @namespace Assert
  2684. * @api public
  2685. */
  2686. assert.notInclude = function (exp, inc, msg) {
  2687. new Assertion(exp, msg, assert.notInclude).not.include(inc);
  2688. };
  2689. /**
  2690. * ### .match(value, regexp, [message])
  2691. *
  2692. * Asserts that `value` matches the regular expression `regexp`.
  2693. *
  2694. * assert.match('foobar', /^foo/, 'regexp matches');
  2695. *
  2696. * @name match
  2697. * @param {Mixed} value
  2698. * @param {RegExp} regexp
  2699. * @param {String} message
  2700. * @namespace Assert
  2701. * @api public
  2702. */
  2703. assert.match = function (exp, re, msg) {
  2704. new Assertion(exp, msg).to.match(re);
  2705. };
  2706. /**
  2707. * ### .notMatch(value, regexp, [message])
  2708. *
  2709. * Asserts that `value` does not match the regular expression `regexp`.
  2710. *
  2711. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  2712. *
  2713. * @name notMatch
  2714. * @param {Mixed} value
  2715. * @param {RegExp} regexp
  2716. * @param {String} message
  2717. * @namespace Assert
  2718. * @api public
  2719. */
  2720. assert.notMatch = function (exp, re, msg) {
  2721. new Assertion(exp, msg).to.not.match(re);
  2722. };
  2723. /**
  2724. * ### .property(object, property, [message])
  2725. *
  2726. * Asserts that `object` has a property named by `property`.
  2727. *
  2728. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  2729. *
  2730. * @name property
  2731. * @param {Object} object
  2732. * @param {String} property
  2733. * @param {String} message
  2734. * @namespace Assert
  2735. * @api public
  2736. */
  2737. assert.property = function (obj, prop, msg) {
  2738. new Assertion(obj, msg).to.have.property(prop);
  2739. };
  2740. /**
  2741. * ### .notProperty(object, property, [message])
  2742. *
  2743. * Asserts that `object` does _not_ have a property named by `property`.
  2744. *
  2745. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  2746. *
  2747. * @name notProperty
  2748. * @param {Object} object
  2749. * @param {String} property
  2750. * @param {String} message
  2751. * @namespace Assert
  2752. * @api public
  2753. */
  2754. assert.notProperty = function (obj, prop, msg) {
  2755. new Assertion(obj, msg).to.not.have.property(prop);
  2756. };
  2757. /**
  2758. * ### .deepProperty(object, property, [message])
  2759. *
  2760. * Asserts that `object` has a property named by `property`, which can be a
  2761. * string using dot- and bracket-notation for deep reference.
  2762. *
  2763. * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
  2764. *
  2765. * @name deepProperty
  2766. * @param {Object} object
  2767. * @param {String} property
  2768. * @param {String} message
  2769. * @namespace Assert
  2770. * @api public
  2771. */
  2772. assert.deepProperty = function (obj, prop, msg) {
  2773. new Assertion(obj, msg).to.have.deep.property(prop);
  2774. };
  2775. /**
  2776. * ### .notDeepProperty(object, property, [message])
  2777. *
  2778. * Asserts that `object` does _not_ have a property named by `property`, which
  2779. * can be a string using dot- and bracket-notation for deep reference.
  2780. *
  2781. * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  2782. *
  2783. * @name notDeepProperty
  2784. * @param {Object} object
  2785. * @param {String} property
  2786. * @param {String} message
  2787. * @namespace Assert
  2788. * @api public
  2789. */
  2790. assert.notDeepProperty = function (obj, prop, msg) {
  2791. new Assertion(obj, msg).to.not.have.deep.property(prop);
  2792. };
  2793. /**
  2794. * ### .propertyVal(object, property, value, [message])
  2795. *
  2796. * Asserts that `object` has a property named by `property` with value given
  2797. * by `value`.
  2798. *
  2799. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  2800. *
  2801. * @name propertyVal
  2802. * @param {Object} object
  2803. * @param {String} property
  2804. * @param {Mixed} value
  2805. * @param {String} message
  2806. * @namespace Assert
  2807. * @api public
  2808. */
  2809. assert.propertyVal = function (obj, prop, val, msg) {
  2810. new Assertion(obj, msg).to.have.property(prop, val);
  2811. };
  2812. /**
  2813. * ### .propertyNotVal(object, property, value, [message])
  2814. *
  2815. * Asserts that `object` has a property named by `property`, but with a value
  2816. * different from that given by `value`.
  2817. *
  2818. * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
  2819. *
  2820. * @name propertyNotVal
  2821. * @param {Object} object
  2822. * @param {String} property
  2823. * @param {Mixed} value
  2824. * @param {String} message
  2825. * @namespace Assert
  2826. * @api public
  2827. */
  2828. assert.propertyNotVal = function (obj, prop, val, msg) {
  2829. new Assertion(obj, msg).to.not.have.property(prop, val);
  2830. };
  2831. /**
  2832. * ### .deepPropertyVal(object, property, value, [message])
  2833. *
  2834. * Asserts that `object` has a property named by `property` with value given
  2835. * by `value`. `property` can use dot- and bracket-notation for deep
  2836. * reference.
  2837. *
  2838. * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  2839. *
  2840. * @name deepPropertyVal
  2841. * @param {Object} object
  2842. * @param {String} property
  2843. * @param {Mixed} value
  2844. * @param {String} message
  2845. * @namespace Assert
  2846. * @api public
  2847. */
  2848. assert.deepPropertyVal = function (obj, prop, val, msg) {
  2849. new Assertion(obj, msg).to.have.deep.property(prop, val);
  2850. };
  2851. /**
  2852. * ### .deepPropertyNotVal(object, property, value, [message])
  2853. *
  2854. * Asserts that `object` has a property named by `property`, but with a value
  2855. * different from that given by `value`. `property` can use dot- and
  2856. * bracket-notation for deep reference.
  2857. *
  2858. * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  2859. *
  2860. * @name deepPropertyNotVal
  2861. * @param {Object} object
  2862. * @param {String} property
  2863. * @param {Mixed} value
  2864. * @param {String} message
  2865. * @namespace Assert
  2866. * @api public
  2867. */
  2868. assert.deepPropertyNotVal = function (obj, prop, val, msg) {
  2869. new Assertion(obj, msg).to.not.have.deep.property(prop, val);
  2870. };
  2871. /**
  2872. * ### .lengthOf(object, length, [message])
  2873. *
  2874. * Asserts that `object` has a `length` property with the expected value.
  2875. *
  2876. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  2877. * assert.lengthOf('foobar', 6, 'string has length of 6');
  2878. *
  2879. * @name lengthOf
  2880. * @param {Mixed} object
  2881. * @param {Number} length
  2882. * @param {String} message
  2883. * @namespace Assert
  2884. * @api public
  2885. */
  2886. assert.lengthOf = function (exp, len, msg) {
  2887. new Assertion(exp, msg).to.have.length(len);
  2888. };
  2889. /**
  2890. * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
  2891. *
  2892. * Asserts that `function` will throw an error that is an instance of
  2893. * `constructor`, or alternately that it will throw an error with message
  2894. * matching `regexp`.
  2895. *
  2896. * assert.throws(fn, 'function throws a reference error');
  2897. * assert.throws(fn, /function throws a reference error/);
  2898. * assert.throws(fn, ReferenceError);
  2899. * assert.throws(fn, ReferenceError, 'function throws a reference error');
  2900. * assert.throws(fn, ReferenceError, /function throws a reference error/);
  2901. *
  2902. * @name throws
  2903. * @alias throw
  2904. * @alias Throw
  2905. * @param {Function} function
  2906. * @param {ErrorConstructor} constructor
  2907. * @param {RegExp} regexp
  2908. * @param {String} message
  2909. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2910. * @namespace Assert
  2911. * @api public
  2912. */
  2913. assert.throws = function (fn, errt, errs, msg) {
  2914. if ('string' === typeof errt || errt instanceof RegExp) {
  2915. errs = errt;
  2916. errt = null;
  2917. }
  2918. var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
  2919. return flag(assertErr, 'object');
  2920. };
  2921. /**
  2922. * ### .doesNotThrow(function, [constructor/regexp], [message])
  2923. *
  2924. * Asserts that `function` will _not_ throw an error that is an instance of
  2925. * `constructor`, or alternately that it will not throw an error with message
  2926. * matching `regexp`.
  2927. *
  2928. * assert.doesNotThrow(fn, Error, 'function does not throw');
  2929. *
  2930. * @name doesNotThrow
  2931. * @param {Function} function
  2932. * @param {ErrorConstructor} constructor
  2933. * @param {RegExp} regexp
  2934. * @param {String} message
  2935. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2936. * @namespace Assert
  2937. * @api public
  2938. */
  2939. assert.doesNotThrow = function (fn, type, msg) {
  2940. if ('string' === typeof type) {
  2941. msg = type;
  2942. type = null;
  2943. }
  2944. new Assertion(fn, msg).to.not.Throw(type);
  2945. };
  2946. /**
  2947. * ### .operator(val1, operator, val2, [message])
  2948. *
  2949. * Compares two values using `operator`.
  2950. *
  2951. * assert.operator(1, '<', 2, 'everything is ok');
  2952. * assert.operator(1, '>', 2, 'this will fail');
  2953. *
  2954. * @name operator
  2955. * @param {Mixed} val1
  2956. * @param {String} operator
  2957. * @param {Mixed} val2
  2958. * @param {String} message
  2959. * @namespace Assert
  2960. * @api public
  2961. */
  2962. assert.operator = function (val, operator, val2, msg) {
  2963. var ok;
  2964. switch(operator) {
  2965. case '==':
  2966. ok = val == val2;
  2967. break;
  2968. case '===':
  2969. ok = val === val2;
  2970. break;
  2971. case '>':
  2972. ok = val > val2;
  2973. break;
  2974. case '>=':
  2975. ok = val >= val2;
  2976. break;
  2977. case '<':
  2978. ok = val < val2;
  2979. break;
  2980. case '<=':
  2981. ok = val <= val2;
  2982. break;
  2983. case '!=':
  2984. ok = val != val2;
  2985. break;
  2986. case '!==':
  2987. ok = val !== val2;
  2988. break;
  2989. default:
  2990. throw new Error('Invalid operator "' + operator + '"');
  2991. }
  2992. var test = new Assertion(ok, msg);
  2993. test.assert(
  2994. true === flag(test, 'object')
  2995. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  2996. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  2997. };
  2998. /**
  2999. * ### .closeTo(actual, expected, delta, [message])
  3000. *
  3001. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  3002. *
  3003. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  3004. *
  3005. * @name closeTo
  3006. * @param {Number} actual
  3007. * @param {Number} expected
  3008. * @param {Number} delta
  3009. * @param {String} message
  3010. * @namespace Assert
  3011. * @api public
  3012. */
  3013. assert.closeTo = function (act, exp, delta, msg) {
  3014. new Assertion(act, msg).to.be.closeTo(exp, delta);
  3015. };
  3016. /**
  3017. * ### .approximately(actual, expected, delta, [message])
  3018. *
  3019. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  3020. *
  3021. * assert.approximately(1.5, 1, 0.5, 'numbers are close');
  3022. *
  3023. * @name approximately
  3024. * @param {Number} actual
  3025. * @param {Number} expected
  3026. * @param {Number} delta
  3027. * @param {String} message
  3028. * @namespace Assert
  3029. * @api public
  3030. */
  3031. assert.approximately = function (act, exp, delta, msg) {
  3032. new Assertion(act, msg).to.be.approximately(exp, delta);
  3033. };
  3034. /**
  3035. * ### .sameMembers(set1, set2, [message])
  3036. *
  3037. * Asserts that `set1` and `set2` have the same members.
  3038. * Order is not taken into account.
  3039. *
  3040. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  3041. *
  3042. * @name sameMembers
  3043. * @param {Array} set1
  3044. * @param {Array} set2
  3045. * @param {String} message
  3046. * @namespace Assert
  3047. * @api public
  3048. */
  3049. assert.sameMembers = function (set1, set2, msg) {
  3050. new Assertion(set1, msg).to.have.same.members(set2);
  3051. }
  3052. /**
  3053. * ### .sameDeepMembers(set1, set2, [message])
  3054. *
  3055. * Asserts that `set1` and `set2` have the same members - using a deep equality checking.
  3056. * Order is not taken into account.
  3057. *
  3058. * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
  3059. *
  3060. * @name sameDeepMembers
  3061. * @param {Array} set1
  3062. * @param {Array} set2
  3063. * @param {String} message
  3064. * @namespace Assert
  3065. * @api public
  3066. */
  3067. assert.sameDeepMembers = function (set1, set2, msg) {
  3068. new Assertion(set1, msg).to.have.same.deep.members(set2);
  3069. }
  3070. /**
  3071. * ### .includeMembers(superset, subset, [message])
  3072. *
  3073. * Asserts that `subset` is included in `superset`.
  3074. * Order is not taken into account.
  3075. *
  3076. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
  3077. *
  3078. * @name includeMembers
  3079. * @param {Array} superset
  3080. * @param {Array} subset
  3081. * @param {String} message
  3082. * @namespace Assert
  3083. * @api public
  3084. */
  3085. assert.includeMembers = function (superset, subset, msg) {
  3086. new Assertion(superset, msg).to.include.members(subset);
  3087. }
  3088. /**
  3089. * ### .includeDeepMembers(superset, subset, [message])
  3090. *
  3091. * Asserts that `subset` is included in `superset` - using deep equality checking.
  3092. * Order is not taken into account.
  3093. * Duplicates are ignored.
  3094. *
  3095. * assert.includeDeepMembers([ {a: 1}, {b: 2}, {c: 3} ], [ {b: 2}, {a: 1}, {b: 2} ], 'include deep members');
  3096. *
  3097. * @name includeDeepMembers
  3098. * @param {Array} superset
  3099. * @param {Array} subset
  3100. * @param {String} message
  3101. * @namespace Assert
  3102. * @api public
  3103. */
  3104. assert.includeDeepMembers = function (superset, subset, msg) {
  3105. new Assertion(superset, msg).to.include.deep.members(subset);
  3106. }
  3107. /**
  3108. * ### .oneOf(inList, list, [message])
  3109. *
  3110. * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
  3111. *
  3112. * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
  3113. *
  3114. * @name oneOf
  3115. * @param {*} inList
  3116. * @param {Array<*>} list
  3117. * @param {String} message
  3118. * @namespace Assert
  3119. * @api public
  3120. */
  3121. assert.oneOf = function (inList, list, msg) {
  3122. new Assertion(inList, msg).to.be.oneOf(list);
  3123. }
  3124. /**
  3125. * ### .changes(function, object, property)
  3126. *
  3127. * Asserts that a function changes the value of a property
  3128. *
  3129. * var obj = { val: 10 };
  3130. * var fn = function() { obj.val = 22 };
  3131. * assert.changes(fn, obj, 'val');
  3132. *
  3133. * @name changes
  3134. * @param {Function} modifier function
  3135. * @param {Object} object
  3136. * @param {String} property name
  3137. * @param {String} message _optional_
  3138. * @namespace Assert
  3139. * @api public
  3140. */
  3141. assert.changes = function (fn, obj, prop) {
  3142. new Assertion(fn).to.change(obj, prop);
  3143. }
  3144. /**
  3145. * ### .doesNotChange(function, object, property)
  3146. *
  3147. * Asserts that a function does not changes the value of a property
  3148. *
  3149. * var obj = { val: 10 };
  3150. * var fn = function() { console.log('foo'); };
  3151. * assert.doesNotChange(fn, obj, 'val');
  3152. *
  3153. * @name doesNotChange
  3154. * @param {Function} modifier function
  3155. * @param {Object} object
  3156. * @param {String} property name
  3157. * @param {String} message _optional_
  3158. * @namespace Assert
  3159. * @api public
  3160. */
  3161. assert.doesNotChange = function (fn, obj, prop) {
  3162. new Assertion(fn).to.not.change(obj, prop);
  3163. }
  3164. /**
  3165. * ### .increases(function, object, property)
  3166. *
  3167. * Asserts that a function increases an object property
  3168. *
  3169. * var obj = { val: 10 };
  3170. * var fn = function() { obj.val = 13 };
  3171. * assert.increases(fn, obj, 'val');
  3172. *
  3173. * @name increases
  3174. * @param {Function} modifier function
  3175. * @param {Object} object
  3176. * @param {String} property name
  3177. * @param {String} message _optional_
  3178. * @namespace Assert
  3179. * @api public
  3180. */
  3181. assert.increases = function (fn, obj, prop) {
  3182. new Assertion(fn).to.increase(obj, prop);
  3183. }
  3184. /**
  3185. * ### .doesNotIncrease(function, object, property)
  3186. *
  3187. * Asserts that a function does not increase object property
  3188. *
  3189. * var obj = { val: 10 };
  3190. * var fn = function() { obj.val = 8 };
  3191. * assert.doesNotIncrease(fn, obj, 'val');
  3192. *
  3193. * @name doesNotIncrease
  3194. * @param {Function} modifier function
  3195. * @param {Object} object
  3196. * @param {String} property name
  3197. * @param {String} message _optional_
  3198. * @namespace Assert
  3199. * @api public
  3200. */
  3201. assert.doesNotIncrease = function (fn, obj, prop) {
  3202. new Assertion(fn).to.not.increase(obj, prop);
  3203. }
  3204. /**
  3205. * ### .decreases(function, object, property)
  3206. *
  3207. * Asserts that a function decreases an object property
  3208. *
  3209. * var obj = { val: 10 };
  3210. * var fn = function() { obj.val = 5 };
  3211. * assert.decreases(fn, obj, 'val');
  3212. *
  3213. * @name decreases
  3214. * @param {Function} modifier function
  3215. * @param {Object} object
  3216. * @param {String} property name
  3217. * @param {String} message _optional_
  3218. * @namespace Assert
  3219. * @api public
  3220. */
  3221. assert.decreases = function (fn, obj, prop) {
  3222. new Assertion(fn).to.decrease(obj, prop);
  3223. }
  3224. /**
  3225. * ### .doesNotDecrease(function, object, property)
  3226. *
  3227. * Asserts that a function does not decreases an object property
  3228. *
  3229. * var obj = { val: 10 };
  3230. * var fn = function() { obj.val = 15 };
  3231. * assert.doesNotDecrease(fn, obj, 'val');
  3232. *
  3233. * @name doesNotDecrease
  3234. * @param {Function} modifier function
  3235. * @param {Object} object
  3236. * @param {String} property name
  3237. * @param {String} message _optional_
  3238. * @namespace Assert
  3239. * @api public
  3240. */
  3241. assert.doesNotDecrease = function (fn, obj, prop) {
  3242. new Assertion(fn).to.not.decrease(obj, prop);
  3243. }
  3244. /*!
  3245. * ### .ifError(object)
  3246. *
  3247. * Asserts if value is not a false value, and throws if it is a true value.
  3248. * This is added to allow for chai to be a drop-in replacement for Node's
  3249. * assert class.
  3250. *
  3251. * var err = new Error('I am a custom error');
  3252. * assert.ifError(err); // Rethrows err!
  3253. *
  3254. * @name ifError
  3255. * @param {Object} object
  3256. * @namespace Assert
  3257. * @api public
  3258. */
  3259. assert.ifError = function (val) {
  3260. if (val) {
  3261. throw(val);
  3262. }
  3263. };
  3264. /**
  3265. * ### .isExtensible(object)
  3266. *
  3267. * Asserts that `object` is extensible (can have new properties added to it).
  3268. *
  3269. * assert.isExtensible({});
  3270. *
  3271. * @name isExtensible
  3272. * @alias extensible
  3273. * @param {Object} object
  3274. * @param {String} message _optional_
  3275. * @namespace Assert
  3276. * @api public
  3277. */
  3278. assert.isExtensible = function (obj, msg) {
  3279. new Assertion(obj, msg).to.be.extensible;
  3280. };
  3281. /**
  3282. * ### .isNotExtensible(object)
  3283. *
  3284. * Asserts that `object` is _not_ extensible.
  3285. *
  3286. * var nonExtensibleObject = Object.preventExtensions({});
  3287. * var sealedObject = Object.seal({});
  3288. * var frozenObject = Object.freese({});
  3289. *
  3290. * assert.isNotExtensible(nonExtensibleObject);
  3291. * assert.isNotExtensible(sealedObject);
  3292. * assert.isNotExtensible(frozenObject);
  3293. *
  3294. * @name isNotExtensible
  3295. * @alias notExtensible
  3296. * @param {Object} object
  3297. * @param {String} message _optional_
  3298. * @namespace Assert
  3299. * @api public
  3300. */
  3301. assert.isNotExtensible = function (obj, msg) {
  3302. new Assertion(obj, msg).to.not.be.extensible;
  3303. };
  3304. /**
  3305. * ### .isSealed(object)
  3306. *
  3307. * Asserts that `object` is sealed (cannot have new properties added to it
  3308. * and its existing properties cannot be removed).
  3309. *
  3310. * var sealedObject = Object.seal({});
  3311. * var frozenObject = Object.seal({});
  3312. *
  3313. * assert.isSealed(sealedObject);
  3314. * assert.isSealed(frozenObject);
  3315. *
  3316. * @name isSealed
  3317. * @alias sealed
  3318. * @param {Object} object
  3319. * @param {String} message _optional_
  3320. * @namespace Assert
  3321. * @api public
  3322. */
  3323. assert.isSealed = function (obj, msg) {
  3324. new Assertion(obj, msg).to.be.sealed;
  3325. };
  3326. /**
  3327. * ### .isNotSealed(object)
  3328. *
  3329. * Asserts that `object` is _not_ sealed.
  3330. *
  3331. * assert.isNotSealed({});
  3332. *
  3333. * @name isNotSealed
  3334. * @alias notSealed
  3335. * @param {Object} object
  3336. * @param {String} message _optional_
  3337. * @namespace Assert
  3338. * @api public
  3339. */
  3340. assert.isNotSealed = function (obj, msg) {
  3341. new Assertion(obj, msg).to.not.be.sealed;
  3342. };
  3343. /**
  3344. * ### .isFrozen(object)
  3345. *
  3346. * Asserts that `object` is frozen (cannot have new properties added to it
  3347. * and its existing properties cannot be modified).
  3348. *
  3349. * var frozenObject = Object.freeze({});
  3350. * assert.frozen(frozenObject);
  3351. *
  3352. * @name isFrozen
  3353. * @alias frozen
  3354. * @param {Object} object
  3355. * @param {String} message _optional_
  3356. * @namespace Assert
  3357. * @api public
  3358. */
  3359. assert.isFrozen = function (obj, msg) {
  3360. new Assertion(obj, msg).to.be.frozen;
  3361. };
  3362. /**
  3363. * ### .isNotFrozen(object)
  3364. *
  3365. * Asserts that `object` is _not_ frozen.
  3366. *
  3367. * assert.isNotFrozen({});
  3368. *
  3369. * @name isNotFrozen
  3370. * @alias notFrozen
  3371. * @param {Object} object
  3372. * @param {String} message _optional_
  3373. * @namespace Assert
  3374. * @api public
  3375. */
  3376. assert.isNotFrozen = function (obj, msg) {
  3377. new Assertion(obj, msg).to.not.be.frozen;
  3378. };
  3379. /*!
  3380. * Aliases.
  3381. */
  3382. (function alias(name, as){
  3383. assert[as] = assert[name];
  3384. return alias;
  3385. })
  3386. ('isOk', 'ok')
  3387. ('isNotOk', 'notOk')
  3388. ('throws', 'throw')
  3389. ('throws', 'Throw')
  3390. ('isExtensible', 'extensible')
  3391. ('isNotExtensible', 'notExtensible')
  3392. ('isSealed', 'sealed')
  3393. ('isNotSealed', 'notSealed')
  3394. ('isFrozen', 'frozen')
  3395. ('isNotFrozen', 'notFrozen');
  3396. };
  3397. },{}],7:[function(require,module,exports){
  3398. /*!
  3399. * chai
  3400. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3401. * MIT Licensed
  3402. */
  3403. module.exports = function (chai, util) {
  3404. chai.expect = function (val, message) {
  3405. return new chai.Assertion(val, message);
  3406. };
  3407. /**
  3408. * ### .fail(actual, expected, [message], [operator])
  3409. *
  3410. * Throw a failure.
  3411. *
  3412. * @name fail
  3413. * @param {Mixed} actual
  3414. * @param {Mixed} expected
  3415. * @param {String} message
  3416. * @param {String} operator
  3417. * @namespace Expect
  3418. * @api public
  3419. */
  3420. chai.expect.fail = function (actual, expected, message, operator) {
  3421. message = message || 'expect.fail()';
  3422. throw new chai.AssertionError(message, {
  3423. actual: actual
  3424. , expected: expected
  3425. , operator: operator
  3426. }, chai.expect.fail);
  3427. };
  3428. };
  3429. },{}],8:[function(require,module,exports){
  3430. /*!
  3431. * chai
  3432. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3433. * MIT Licensed
  3434. */
  3435. module.exports = function (chai, util) {
  3436. var Assertion = chai.Assertion;
  3437. function loadShould () {
  3438. // explicitly define this method as function as to have it's name to include as `ssfi`
  3439. function shouldGetter() {
  3440. if (this instanceof String || this instanceof Number || this instanceof Boolean ) {
  3441. return new Assertion(this.valueOf(), null, shouldGetter);
  3442. }
  3443. return new Assertion(this, null, shouldGetter);
  3444. }
  3445. function shouldSetter(value) {
  3446. // See https://github.com/chaijs/chai/issues/86: this makes
  3447. // `whatever.should = someValue` actually set `someValue`, which is
  3448. // especially useful for `global.should = require('chai').should()`.
  3449. //
  3450. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  3451. // since otherwise we would trigger this very setter!
  3452. Object.defineProperty(this, 'should', {
  3453. value: value,
  3454. enumerable: true,
  3455. configurable: true,
  3456. writable: true
  3457. });
  3458. }
  3459. // modify Object.prototype to have `should`
  3460. Object.defineProperty(Object.prototype, 'should', {
  3461. set: shouldSetter
  3462. , get: shouldGetter
  3463. , configurable: true
  3464. });
  3465. var should = {};
  3466. /**
  3467. * ### .fail(actual, expected, [message], [operator])
  3468. *
  3469. * Throw a failure.
  3470. *
  3471. * @name fail
  3472. * @param {Mixed} actual
  3473. * @param {Mixed} expected
  3474. * @param {String} message
  3475. * @param {String} operator
  3476. * @namespace Should
  3477. * @api public
  3478. */
  3479. should.fail = function (actual, expected, message, operator) {
  3480. message = message || 'should.fail()';
  3481. throw new chai.AssertionError(message, {
  3482. actual: actual
  3483. , expected: expected
  3484. , operator: operator
  3485. }, should.fail);
  3486. };
  3487. /**
  3488. * ### .equal(actual, expected, [message])
  3489. *
  3490. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  3491. *
  3492. * should.equal(3, '3', '== coerces values to strings');
  3493. *
  3494. * @name equal
  3495. * @param {Mixed} actual
  3496. * @param {Mixed} expected
  3497. * @param {String} message
  3498. * @namespace Should
  3499. * @api public
  3500. */
  3501. should.equal = function (val1, val2, msg) {
  3502. new Assertion(val1, msg).to.equal(val2);
  3503. };
  3504. /**
  3505. * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
  3506. *
  3507. * Asserts that `function` will throw an error that is an instance of
  3508. * `constructor`, or alternately that it will throw an error with message
  3509. * matching `regexp`.
  3510. *
  3511. * should.throw(fn, 'function throws a reference error');
  3512. * should.throw(fn, /function throws a reference error/);
  3513. * should.throw(fn, ReferenceError);
  3514. * should.throw(fn, ReferenceError, 'function throws a reference error');
  3515. * should.throw(fn, ReferenceError, /function throws a reference error/);
  3516. *
  3517. * @name throw
  3518. * @alias Throw
  3519. * @param {Function} function
  3520. * @param {ErrorConstructor} constructor
  3521. * @param {RegExp} regexp
  3522. * @param {String} message
  3523. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  3524. * @namespace Should
  3525. * @api public
  3526. */
  3527. should.Throw = function (fn, errt, errs, msg) {
  3528. new Assertion(fn, msg).to.Throw(errt, errs);
  3529. };
  3530. /**
  3531. * ### .exist
  3532. *
  3533. * Asserts that the target is neither `null` nor `undefined`.
  3534. *
  3535. * var foo = 'hi';
  3536. *
  3537. * should.exist(foo, 'foo exists');
  3538. *
  3539. * @name exist
  3540. * @namespace Should
  3541. * @api public
  3542. */
  3543. should.exist = function (val, msg) {
  3544. new Assertion(val, msg).to.exist;
  3545. }
  3546. // negation
  3547. should.not = {}
  3548. /**
  3549. * ### .not.equal(actual, expected, [message])
  3550. *
  3551. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  3552. *
  3553. * should.not.equal(3, 4, 'these numbers are not equal');
  3554. *
  3555. * @name not.equal
  3556. * @param {Mixed} actual
  3557. * @param {Mixed} expected
  3558. * @param {String} message
  3559. * @namespace Should
  3560. * @api public
  3561. */
  3562. should.not.equal = function (val1, val2, msg) {
  3563. new Assertion(val1, msg).to.not.equal(val2);
  3564. };
  3565. /**
  3566. * ### .throw(function, [constructor/regexp], [message])
  3567. *
  3568. * Asserts that `function` will _not_ throw an error that is an instance of
  3569. * `constructor`, or alternately that it will not throw an error with message
  3570. * matching `regexp`.
  3571. *
  3572. * should.not.throw(fn, Error, 'function does not throw');
  3573. *
  3574. * @name not.throw
  3575. * @alias not.Throw
  3576. * @param {Function} function
  3577. * @param {ErrorConstructor} constructor
  3578. * @param {RegExp} regexp
  3579. * @param {String} message
  3580. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  3581. * @namespace Should
  3582. * @api public
  3583. */
  3584. should.not.Throw = function (fn, errt, errs, msg) {
  3585. new Assertion(fn, msg).to.not.Throw(errt, errs);
  3586. };
  3587. /**
  3588. * ### .not.exist
  3589. *
  3590. * Asserts that the target is neither `null` nor `undefined`.
  3591. *
  3592. * var bar = null;
  3593. *
  3594. * should.not.exist(bar, 'bar does not exist');
  3595. *
  3596. * @name not.exist
  3597. * @namespace Should
  3598. * @api public
  3599. */
  3600. should.not.exist = function (val, msg) {
  3601. new Assertion(val, msg).to.not.exist;
  3602. }
  3603. should['throw'] = should['Throw'];
  3604. should.not['throw'] = should.not['Throw'];
  3605. return should;
  3606. };
  3607. chai.should = loadShould;
  3608. chai.Should = loadShould;
  3609. };
  3610. },{}],9:[function(require,module,exports){
  3611. /*!
  3612. * Chai - addChainingMethod utility
  3613. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3614. * MIT Licensed
  3615. */
  3616. /*!
  3617. * Module dependencies
  3618. */
  3619. var transferFlags = require('./transferFlags');
  3620. var flag = require('./flag');
  3621. var config = require('../config');
  3622. /*!
  3623. * Module variables
  3624. */
  3625. // Check whether `__proto__` is supported
  3626. var hasProtoSupport = '__proto__' in Object;
  3627. // Without `__proto__` support, this module will need to add properties to a function.
  3628. // However, some Function.prototype methods cannot be overwritten,
  3629. // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
  3630. var excludeNames = /^(?:length|name|arguments|caller)$/;
  3631. // Cache `Function` properties
  3632. var call = Function.prototype.call,
  3633. apply = Function.prototype.apply;
  3634. /**
  3635. * ### addChainableMethod (ctx, name, method, chainingBehavior)
  3636. *
  3637. * Adds a method to an object, such that the method can also be chained.
  3638. *
  3639. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  3640. * var obj = utils.flag(this, 'object');
  3641. * new chai.Assertion(obj).to.be.equal(str);
  3642. * });
  3643. *
  3644. * Can also be accessed directly from `chai.Assertion`.
  3645. *
  3646. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  3647. *
  3648. * The result can then be used as both a method assertion, executing both `method` and
  3649. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  3650. *
  3651. * expect(fooStr).to.be.foo('bar');
  3652. * expect(fooStr).to.be.foo.equal('foo');
  3653. *
  3654. * @param {Object} ctx object to which the method is added
  3655. * @param {String} name of method to add
  3656. * @param {Function} method function to be used for `name`, when called
  3657. * @param {Function} chainingBehavior function to be called every time the property is accessed
  3658. * @namespace Utils
  3659. * @name addChainableMethod
  3660. * @api public
  3661. */
  3662. module.exports = function (ctx, name, method, chainingBehavior) {
  3663. if (typeof chainingBehavior !== 'function') {
  3664. chainingBehavior = function () { };
  3665. }
  3666. var chainableBehavior = {
  3667. method: method
  3668. , chainingBehavior: chainingBehavior
  3669. };
  3670. // save the methods so we can overwrite them later, if we need to.
  3671. if (!ctx.__methods) {
  3672. ctx.__methods = {};
  3673. }
  3674. ctx.__methods[name] = chainableBehavior;
  3675. Object.defineProperty(ctx, name,
  3676. { get: function () {
  3677. chainableBehavior.chainingBehavior.call(this);
  3678. var assert = function assert() {
  3679. var old_ssfi = flag(this, 'ssfi');
  3680. if (old_ssfi && config.includeStack === false)
  3681. flag(this, 'ssfi', assert);
  3682. var result = chainableBehavior.method.apply(this, arguments);
  3683. return result === undefined ? this : result;
  3684. };
  3685. // Use `__proto__` if available
  3686. if (hasProtoSupport) {
  3687. // Inherit all properties from the object by replacing the `Function` prototype
  3688. var prototype = assert.__proto__ = Object.create(this);
  3689. // Restore the `call` and `apply` methods from `Function`
  3690. prototype.call = call;
  3691. prototype.apply = apply;
  3692. }
  3693. // Otherwise, redefine all properties (slow!)
  3694. else {
  3695. var asserterNames = Object.getOwnPropertyNames(ctx);
  3696. asserterNames.forEach(function (asserterName) {
  3697. if (!excludeNames.test(asserterName)) {
  3698. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  3699. Object.defineProperty(assert, asserterName, pd);
  3700. }
  3701. });
  3702. }
  3703. transferFlags(this, assert);
  3704. return assert;
  3705. }
  3706. , configurable: true
  3707. });
  3708. };
  3709. },{"../config":4,"./flag":13,"./transferFlags":29}],10:[function(require,module,exports){
  3710. /*!
  3711. * Chai - addMethod utility
  3712. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3713. * MIT Licensed
  3714. */
  3715. var config = require('../config');
  3716. /**
  3717. * ### .addMethod (ctx, name, method)
  3718. *
  3719. * Adds a method to the prototype of an object.
  3720. *
  3721. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  3722. * var obj = utils.flag(this, 'object');
  3723. * new chai.Assertion(obj).to.be.equal(str);
  3724. * });
  3725. *
  3726. * Can also be accessed directly from `chai.Assertion`.
  3727. *
  3728. * chai.Assertion.addMethod('foo', fn);
  3729. *
  3730. * Then can be used as any other assertion.
  3731. *
  3732. * expect(fooStr).to.be.foo('bar');
  3733. *
  3734. * @param {Object} ctx object to which the method is added
  3735. * @param {String} name of method to add
  3736. * @param {Function} method function to be used for name
  3737. * @namespace Utils
  3738. * @name addMethod
  3739. * @api public
  3740. */
  3741. var flag = require('./flag');
  3742. module.exports = function (ctx, name, method) {
  3743. ctx[name] = function () {
  3744. var old_ssfi = flag(this, 'ssfi');
  3745. if (old_ssfi && config.includeStack === false)
  3746. flag(this, 'ssfi', ctx[name]);
  3747. var result = method.apply(this, arguments);
  3748. return result === undefined ? this : result;
  3749. };
  3750. };
  3751. },{"../config":4,"./flag":13}],11:[function(require,module,exports){
  3752. /*!
  3753. * Chai - addProperty utility
  3754. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3755. * MIT Licensed
  3756. */
  3757. var config = require('../config');
  3758. var flag = require('./flag');
  3759. /**
  3760. * ### addProperty (ctx, name, getter)
  3761. *
  3762. * Adds a property to the prototype of an object.
  3763. *
  3764. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  3765. * var obj = utils.flag(this, 'object');
  3766. * new chai.Assertion(obj).to.be.instanceof(Foo);
  3767. * });
  3768. *
  3769. * Can also be accessed directly from `chai.Assertion`.
  3770. *
  3771. * chai.Assertion.addProperty('foo', fn);
  3772. *
  3773. * Then can be used as any other assertion.
  3774. *
  3775. * expect(myFoo).to.be.foo;
  3776. *
  3777. * @param {Object} ctx object to which the property is added
  3778. * @param {String} name of property to add
  3779. * @param {Function} getter function to be used for name
  3780. * @namespace Utils
  3781. * @name addProperty
  3782. * @api public
  3783. */
  3784. module.exports = function (ctx, name, getter) {
  3785. Object.defineProperty(ctx, name,
  3786. { get: function addProperty() {
  3787. var old_ssfi = flag(this, 'ssfi');
  3788. if (old_ssfi && config.includeStack === false)
  3789. flag(this, 'ssfi', addProperty);
  3790. var result = getter.call(this);
  3791. return result === undefined ? this : result;
  3792. }
  3793. , configurable: true
  3794. });
  3795. };
  3796. },{"../config":4,"./flag":13}],12:[function(require,module,exports){
  3797. /*!
  3798. * Chai - expectTypes utility
  3799. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3800. * MIT Licensed
  3801. */
  3802. /**
  3803. * ### expectTypes(obj, types)
  3804. *
  3805. * Ensures that the object being tested against is of a valid type.
  3806. *
  3807. * utils.expectTypes(this, ['array', 'object', 'string']);
  3808. *
  3809. * @param {Mixed} obj constructed Assertion
  3810. * @param {Array} type A list of allowed types for this assertion
  3811. * @namespace Utils
  3812. * @name expectTypes
  3813. * @api public
  3814. */
  3815. var AssertionError = require('assertion-error');
  3816. var flag = require('./flag');
  3817. var type = require('type-detect');
  3818. module.exports = function (obj, types) {
  3819. var obj = flag(obj, 'object');
  3820. types = types.map(function (t) { return t.toLowerCase(); });
  3821. types.sort();
  3822. // Transforms ['lorem', 'ipsum'] into 'a lirum, or an ipsum'
  3823. var str = types.map(function (t, index) {
  3824. var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
  3825. var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
  3826. return or + art + ' ' + t;
  3827. }).join(', ');
  3828. if (!types.some(function (expected) { return type(obj) === expected; })) {
  3829. throw new AssertionError(
  3830. 'object tested must be ' + str + ', but ' + type(obj) + ' given'
  3831. );
  3832. }
  3833. };
  3834. },{"./flag":13,"assertion-error":30,"type-detect":35}],13:[function(require,module,exports){
  3835. /*!
  3836. * Chai - flag utility
  3837. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3838. * MIT Licensed
  3839. */
  3840. /**
  3841. * ### flag(object, key, [value])
  3842. *
  3843. * Get or set a flag value on an object. If a
  3844. * value is provided it will be set, else it will
  3845. * return the currently set value or `undefined` if
  3846. * the value is not set.
  3847. *
  3848. * utils.flag(this, 'foo', 'bar'); // setter
  3849. * utils.flag(this, 'foo'); // getter, returns `bar`
  3850. *
  3851. * @param {Object} object constructed Assertion
  3852. * @param {String} key
  3853. * @param {Mixed} value (optional)
  3854. * @namespace Utils
  3855. * @name flag
  3856. * @api private
  3857. */
  3858. module.exports = function (obj, key, value) {
  3859. var flags = obj.__flags || (obj.__flags = Object.create(null));
  3860. if (arguments.length === 3) {
  3861. flags[key] = value;
  3862. } else {
  3863. return flags[key];
  3864. }
  3865. };
  3866. },{}],14:[function(require,module,exports){
  3867. /*!
  3868. * Chai - getActual utility
  3869. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3870. * MIT Licensed
  3871. */
  3872. /**
  3873. * # getActual(object, [actual])
  3874. *
  3875. * Returns the `actual` value for an Assertion
  3876. *
  3877. * @param {Object} object (constructed Assertion)
  3878. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3879. * @namespace Utils
  3880. * @name getActual
  3881. */
  3882. module.exports = function (obj, args) {
  3883. return args.length > 4 ? args[4] : obj._obj;
  3884. };
  3885. },{}],15:[function(require,module,exports){
  3886. /*!
  3887. * Chai - getEnumerableProperties utility
  3888. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3889. * MIT Licensed
  3890. */
  3891. /**
  3892. * ### .getEnumerableProperties(object)
  3893. *
  3894. * This allows the retrieval of enumerable property names of an object,
  3895. * inherited or not.
  3896. *
  3897. * @param {Object} object
  3898. * @returns {Array}
  3899. * @namespace Utils
  3900. * @name getEnumerableProperties
  3901. * @api public
  3902. */
  3903. module.exports = function getEnumerableProperties(object) {
  3904. var result = [];
  3905. for (var name in object) {
  3906. result.push(name);
  3907. }
  3908. return result;
  3909. };
  3910. },{}],16:[function(require,module,exports){
  3911. /*!
  3912. * Chai - message composition utility
  3913. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3914. * MIT Licensed
  3915. */
  3916. /*!
  3917. * Module dependancies
  3918. */
  3919. var flag = require('./flag')
  3920. , getActual = require('./getActual')
  3921. , inspect = require('./inspect')
  3922. , objDisplay = require('./objDisplay');
  3923. /**
  3924. * ### .getMessage(object, message, negateMessage)
  3925. *
  3926. * Construct the error message based on flags
  3927. * and template tags. Template tags will return
  3928. * a stringified inspection of the object referenced.
  3929. *
  3930. * Message template tags:
  3931. * - `#{this}` current asserted object
  3932. * - `#{act}` actual value
  3933. * - `#{exp}` expected value
  3934. *
  3935. * @param {Object} object (constructed Assertion)
  3936. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3937. * @namespace Utils
  3938. * @name getMessage
  3939. * @api public
  3940. */
  3941. module.exports = function (obj, args) {
  3942. var negate = flag(obj, 'negate')
  3943. , val = flag(obj, 'object')
  3944. , expected = args[3]
  3945. , actual = getActual(obj, args)
  3946. , msg = negate ? args[2] : args[1]
  3947. , flagMsg = flag(obj, 'message');
  3948. if(typeof msg === "function") msg = msg();
  3949. msg = msg || '';
  3950. msg = msg
  3951. .replace(/#\{this\}/g, function () { return objDisplay(val); })
  3952. .replace(/#\{act\}/g, function () { return objDisplay(actual); })
  3953. .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
  3954. return flagMsg ? flagMsg + ': ' + msg : msg;
  3955. };
  3956. },{"./flag":13,"./getActual":14,"./inspect":23,"./objDisplay":24}],17:[function(require,module,exports){
  3957. /*!
  3958. * Chai - getName utility
  3959. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3960. * MIT Licensed
  3961. */
  3962. /**
  3963. * # getName(func)
  3964. *
  3965. * Gets the name of a function, in a cross-browser way.
  3966. *
  3967. * @param {Function} a function (usually a constructor)
  3968. * @namespace Utils
  3969. * @name getName
  3970. */
  3971. module.exports = function (func) {
  3972. if (func.name) return func.name;
  3973. var match = /^\s?function ([^(]*)\(/.exec(func);
  3974. return match && match[1] ? match[1] : "";
  3975. };
  3976. },{}],18:[function(require,module,exports){
  3977. /*!
  3978. * Chai - getPathInfo utility
  3979. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3980. * MIT Licensed
  3981. */
  3982. var hasProperty = require('./hasProperty');
  3983. /**
  3984. * ### .getPathInfo(path, object)
  3985. *
  3986. * This allows the retrieval of property info in an
  3987. * object given a string path.
  3988. *
  3989. * The path info consists of an object with the
  3990. * following properties:
  3991. *
  3992. * * parent - The parent object of the property referenced by `path`
  3993. * * name - The name of the final property, a number if it was an array indexer
  3994. * * value - The value of the property, if it exists, otherwise `undefined`
  3995. * * exists - Whether the property exists or not
  3996. *
  3997. * @param {String} path
  3998. * @param {Object} object
  3999. * @returns {Object} info
  4000. * @namespace Utils
  4001. * @name getPathInfo
  4002. * @api public
  4003. */
  4004. module.exports = function getPathInfo(path, obj) {
  4005. var parsed = parsePath(path),
  4006. last = parsed[parsed.length - 1];
  4007. var info = {
  4008. parent: parsed.length > 1 ? _getPathValue(parsed, obj, parsed.length - 1) : obj,
  4009. name: last.p || last.i,
  4010. value: _getPathValue(parsed, obj)
  4011. };
  4012. info.exists = hasProperty(info.name, info.parent);
  4013. return info;
  4014. };
  4015. /*!
  4016. * ## parsePath(path)
  4017. *
  4018. * Helper function used to parse string object
  4019. * paths. Use in conjunction with `_getPathValue`.
  4020. *
  4021. * var parsed = parsePath('myobject.property.subprop');
  4022. *
  4023. * ### Paths:
  4024. *
  4025. * * Can be as near infinitely deep and nested
  4026. * * Arrays are also valid using the formal `myobject.document[3].property`.
  4027. * * Literal dots and brackets (not delimiter) must be backslash-escaped.
  4028. *
  4029. * @param {String} path
  4030. * @returns {Object} parsed
  4031. * @api private
  4032. */
  4033. function parsePath (path) {
  4034. var str = path.replace(/([^\\])\[/g, '$1.[')
  4035. , parts = str.match(/(\\\.|[^.]+?)+/g);
  4036. return parts.map(function (value) {
  4037. var re = /^\[(\d+)\]$/
  4038. , mArr = re.exec(value);
  4039. if (mArr) return { i: parseFloat(mArr[1]) };
  4040. else return { p: value.replace(/\\([.\[\]])/g, '$1') };
  4041. });
  4042. }
  4043. /*!
  4044. * ## _getPathValue(parsed, obj)
  4045. *
  4046. * Helper companion function for `.parsePath` that returns
  4047. * the value located at the parsed address.
  4048. *
  4049. * var value = getPathValue(parsed, obj);
  4050. *
  4051. * @param {Object} parsed definition from `parsePath`.
  4052. * @param {Object} object to search against
  4053. * @param {Number} object to search against
  4054. * @returns {Object|Undefined} value
  4055. * @api private
  4056. */
  4057. function _getPathValue (parsed, obj, index) {
  4058. var tmp = obj
  4059. , res;
  4060. index = (index === undefined ? parsed.length : index);
  4061. for (var i = 0, l = index; i < l; i++) {
  4062. var part = parsed[i];
  4063. if (tmp) {
  4064. if ('undefined' !== typeof part.p)
  4065. tmp = tmp[part.p];
  4066. else if ('undefined' !== typeof part.i)
  4067. tmp = tmp[part.i];
  4068. if (i == (l - 1)) res = tmp;
  4069. } else {
  4070. res = undefined;
  4071. }
  4072. }
  4073. return res;
  4074. }
  4075. },{"./hasProperty":21}],19:[function(require,module,exports){
  4076. /*!
  4077. * Chai - getPathValue utility
  4078. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4079. * @see https://github.com/logicalparadox/filtr
  4080. * MIT Licensed
  4081. */
  4082. var getPathInfo = require('./getPathInfo');
  4083. /**
  4084. * ### .getPathValue(path, object)
  4085. *
  4086. * This allows the retrieval of values in an
  4087. * object given a string path.
  4088. *
  4089. * var obj = {
  4090. * prop1: {
  4091. * arr: ['a', 'b', 'c']
  4092. * , str: 'Hello'
  4093. * }
  4094. * , prop2: {
  4095. * arr: [ { nested: 'Universe' } ]
  4096. * , str: 'Hello again!'
  4097. * }
  4098. * }
  4099. *
  4100. * The following would be the results.
  4101. *
  4102. * getPathValue('prop1.str', obj); // Hello
  4103. * getPathValue('prop1.att[2]', obj); // b
  4104. * getPathValue('prop2.arr[0].nested', obj); // Universe
  4105. *
  4106. * @param {String} path
  4107. * @param {Object} object
  4108. * @returns {Object} value or `undefined`
  4109. * @namespace Utils
  4110. * @name getPathValue
  4111. * @api public
  4112. */
  4113. module.exports = function(path, obj) {
  4114. var info = getPathInfo(path, obj);
  4115. return info.value;
  4116. };
  4117. },{"./getPathInfo":18}],20:[function(require,module,exports){
  4118. /*!
  4119. * Chai - getProperties utility
  4120. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4121. * MIT Licensed
  4122. */
  4123. /**
  4124. * ### .getProperties(object)
  4125. *
  4126. * This allows the retrieval of property names of an object, enumerable or not,
  4127. * inherited or not.
  4128. *
  4129. * @param {Object} object
  4130. * @returns {Array}
  4131. * @namespace Utils
  4132. * @name getProperties
  4133. * @api public
  4134. */
  4135. module.exports = function getProperties(object) {
  4136. var result = Object.getOwnPropertyNames(object);
  4137. function addProperty(property) {
  4138. if (result.indexOf(property) === -1) {
  4139. result.push(property);
  4140. }
  4141. }
  4142. var proto = Object.getPrototypeOf(object);
  4143. while (proto !== null) {
  4144. Object.getOwnPropertyNames(proto).forEach(addProperty);
  4145. proto = Object.getPrototypeOf(proto);
  4146. }
  4147. return result;
  4148. };
  4149. },{}],21:[function(require,module,exports){
  4150. /*!
  4151. * Chai - hasProperty utility
  4152. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4153. * MIT Licensed
  4154. */
  4155. var type = require('type-detect');
  4156. /**
  4157. * ### .hasProperty(object, name)
  4158. *
  4159. * This allows checking whether an object has
  4160. * named property or numeric array index.
  4161. *
  4162. * Basically does the same thing as the `in`
  4163. * operator but works properly with natives
  4164. * and null/undefined values.
  4165. *
  4166. * var obj = {
  4167. * arr: ['a', 'b', 'c']
  4168. * , str: 'Hello'
  4169. * }
  4170. *
  4171. * The following would be the results.
  4172. *
  4173. * hasProperty('str', obj); // true
  4174. * hasProperty('constructor', obj); // true
  4175. * hasProperty('bar', obj); // false
  4176. *
  4177. * hasProperty('length', obj.str); // true
  4178. * hasProperty(1, obj.str); // true
  4179. * hasProperty(5, obj.str); // false
  4180. *
  4181. * hasProperty('length', obj.arr); // true
  4182. * hasProperty(2, obj.arr); // true
  4183. * hasProperty(3, obj.arr); // false
  4184. *
  4185. * @param {Objuect} object
  4186. * @param {String|Number} name
  4187. * @returns {Boolean} whether it exists
  4188. * @namespace Utils
  4189. * @name getPathInfo
  4190. * @api public
  4191. */
  4192. var literals = {
  4193. 'number': Number
  4194. , 'string': String
  4195. };
  4196. module.exports = function hasProperty(name, obj) {
  4197. var ot = type(obj);
  4198. // Bad Object, obviously no props at all
  4199. if(ot === 'null' || ot === 'undefined')
  4200. return false;
  4201. // The `in` operator does not work with certain literals
  4202. // box these before the check
  4203. if(literals[ot] && typeof obj !== 'object')
  4204. obj = new literals[ot](obj);
  4205. return name in obj;
  4206. };
  4207. },{"type-detect":35}],22:[function(require,module,exports){
  4208. /*!
  4209. * chai
  4210. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  4211. * MIT Licensed
  4212. */
  4213. /*!
  4214. * Main exports
  4215. */
  4216. var exports = module.exports = {};
  4217. /*!
  4218. * test utility
  4219. */
  4220. exports.test = require('./test');
  4221. /*!
  4222. * type utility
  4223. */
  4224. exports.type = require('type-detect');
  4225. /*!
  4226. * expectTypes utility
  4227. */
  4228. exports.expectTypes = require('./expectTypes');
  4229. /*!
  4230. * message utility
  4231. */
  4232. exports.getMessage = require('./getMessage');
  4233. /*!
  4234. * actual utility
  4235. */
  4236. exports.getActual = require('./getActual');
  4237. /*!
  4238. * Inspect util
  4239. */
  4240. exports.inspect = require('./inspect');
  4241. /*!
  4242. * Object Display util
  4243. */
  4244. exports.objDisplay = require('./objDisplay');
  4245. /*!
  4246. * Flag utility
  4247. */
  4248. exports.flag = require('./flag');
  4249. /*!
  4250. * Flag transferring utility
  4251. */
  4252. exports.transferFlags = require('./transferFlags');
  4253. /*!
  4254. * Deep equal utility
  4255. */
  4256. exports.eql = require('deep-eql');
  4257. /*!
  4258. * Deep path value
  4259. */
  4260. exports.getPathValue = require('./getPathValue');
  4261. /*!
  4262. * Deep path info
  4263. */
  4264. exports.getPathInfo = require('./getPathInfo');
  4265. /*!
  4266. * Check if a property exists
  4267. */
  4268. exports.hasProperty = require('./hasProperty');
  4269. /*!
  4270. * Function name
  4271. */
  4272. exports.getName = require('./getName');
  4273. /*!
  4274. * add Property
  4275. */
  4276. exports.addProperty = require('./addProperty');
  4277. /*!
  4278. * add Method
  4279. */
  4280. exports.addMethod = require('./addMethod');
  4281. /*!
  4282. * overwrite Property
  4283. */
  4284. exports.overwriteProperty = require('./overwriteProperty');
  4285. /*!
  4286. * overwrite Method
  4287. */
  4288. exports.overwriteMethod = require('./overwriteMethod');
  4289. /*!
  4290. * Add a chainable method
  4291. */
  4292. exports.addChainableMethod = require('./addChainableMethod');
  4293. /*!
  4294. * Overwrite chainable method
  4295. */
  4296. exports.overwriteChainableMethod = require('./overwriteChainableMethod');
  4297. },{"./addChainableMethod":9,"./addMethod":10,"./addProperty":11,"./expectTypes":12,"./flag":13,"./getActual":14,"./getMessage":16,"./getName":17,"./getPathInfo":18,"./getPathValue":19,"./hasProperty":21,"./inspect":23,"./objDisplay":24,"./overwriteChainableMethod":25,"./overwriteMethod":26,"./overwriteProperty":27,"./test":28,"./transferFlags":29,"deep-eql":31,"type-detect":35}],23:[function(require,module,exports){
  4298. // This is (almost) directly from Node.js utils
  4299. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  4300. var getName = require('./getName');
  4301. var getProperties = require('./getProperties');
  4302. var getEnumerableProperties = require('./getEnumerableProperties');
  4303. module.exports = inspect;
  4304. /**
  4305. * Echos the value of a value. Trys to print the value out
  4306. * in the best way possible given the different types.
  4307. *
  4308. * @param {Object} obj The object to print out.
  4309. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  4310. * properties of objects.
  4311. * @param {Number} depth Depth in which to descend in object. Default is 2.
  4312. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  4313. * output. Default is false (no coloring).
  4314. * @namespace Utils
  4315. * @name inspect
  4316. */
  4317. function inspect(obj, showHidden, depth, colors) {
  4318. var ctx = {
  4319. showHidden: showHidden,
  4320. seen: [],
  4321. stylize: function (str) { return str; }
  4322. };
  4323. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  4324. }
  4325. // Returns true if object is a DOM element.
  4326. var isDOMElement = function (object) {
  4327. if (typeof HTMLElement === 'object') {
  4328. return object instanceof HTMLElement;
  4329. } else {
  4330. return object &&
  4331. typeof object === 'object' &&
  4332. object.nodeType === 1 &&
  4333. typeof object.nodeName === 'string';
  4334. }
  4335. };
  4336. function formatValue(ctx, value, recurseTimes) {
  4337. // Provide a hook for user-specified inspect functions.
  4338. // Check that value is an object with an inspect function on it
  4339. if (value && typeof value.inspect === 'function' &&
  4340. // Filter out the util module, it's inspect function is special
  4341. value.inspect !== exports.inspect &&
  4342. // Also filter out any prototype objects using the circular check.
  4343. !(value.constructor && value.constructor.prototype === value)) {
  4344. var ret = value.inspect(recurseTimes);
  4345. if (typeof ret !== 'string') {
  4346. ret = formatValue(ctx, ret, recurseTimes);
  4347. }
  4348. return ret;
  4349. }
  4350. // Primitive types cannot have properties
  4351. var primitive = formatPrimitive(ctx, value);
  4352. if (primitive) {
  4353. return primitive;
  4354. }
  4355. // If this is a DOM element, try to get the outer HTML.
  4356. if (isDOMElement(value)) {
  4357. if ('outerHTML' in value) {
  4358. return value.outerHTML;
  4359. // This value does not have an outerHTML attribute,
  4360. // it could still be an XML element
  4361. } else {
  4362. // Attempt to serialize it
  4363. try {
  4364. if (document.xmlVersion) {
  4365. var xmlSerializer = new XMLSerializer();
  4366. return xmlSerializer.serializeToString(value);
  4367. } else {
  4368. // Firefox 11- do not support outerHTML
  4369. // It does, however, support innerHTML
  4370. // Use the following to render the element
  4371. var ns = "http://www.w3.org/1999/xhtml";
  4372. var container = document.createElementNS(ns, '_');
  4373. container.appendChild(value.cloneNode(false));
  4374. html = container.innerHTML
  4375. .replace('><', '>' + value.innerHTML + '<');
  4376. container.innerHTML = '';
  4377. return html;
  4378. }
  4379. } catch (err) {
  4380. // This could be a non-native DOM implementation,
  4381. // continue with the normal flow:
  4382. // printing the element as if it is an object.
  4383. }
  4384. }
  4385. }
  4386. // Look up the keys of the object.
  4387. var visibleKeys = getEnumerableProperties(value);
  4388. var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
  4389. // Some type of object without properties can be shortcutted.
  4390. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  4391. // a `stack` plus `description` property; ignore those for consistency.
  4392. if (keys.length === 0 || (isError(value) && (
  4393. (keys.length === 1 && keys[0] === 'stack') ||
  4394. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  4395. ))) {
  4396. if (typeof value === 'function') {
  4397. var name = getName(value);
  4398. var nameSuffix = name ? ': ' + name : '';
  4399. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  4400. }
  4401. if (isRegExp(value)) {
  4402. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4403. }
  4404. if (isDate(value)) {
  4405. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  4406. }
  4407. if (isError(value)) {
  4408. return formatError(value);
  4409. }
  4410. }
  4411. var base = '', array = false, braces = ['{', '}'];
  4412. // Make Array say that they are Array
  4413. if (isArray(value)) {
  4414. array = true;
  4415. braces = ['[', ']'];
  4416. }
  4417. // Make functions say that they are functions
  4418. if (typeof value === 'function') {
  4419. var name = getName(value);
  4420. var nameSuffix = name ? ': ' + name : '';
  4421. base = ' [Function' + nameSuffix + ']';
  4422. }
  4423. // Make RegExps say that they are RegExps
  4424. if (isRegExp(value)) {
  4425. base = ' ' + RegExp.prototype.toString.call(value);
  4426. }
  4427. // Make dates with properties first say the date
  4428. if (isDate(value)) {
  4429. base = ' ' + Date.prototype.toUTCString.call(value);
  4430. }
  4431. // Make error with message first say the error
  4432. if (isError(value)) {
  4433. return formatError(value);
  4434. }
  4435. if (keys.length === 0 && (!array || value.length == 0)) {
  4436. return braces[0] + base + braces[1];
  4437. }
  4438. if (recurseTimes < 0) {
  4439. if (isRegExp(value)) {
  4440. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4441. } else {
  4442. return ctx.stylize('[Object]', 'special');
  4443. }
  4444. }
  4445. ctx.seen.push(value);
  4446. var output;
  4447. if (array) {
  4448. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  4449. } else {
  4450. output = keys.map(function(key) {
  4451. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  4452. });
  4453. }
  4454. ctx.seen.pop();
  4455. return reduceToSingleString(output, base, braces);
  4456. }
  4457. function formatPrimitive(ctx, value) {
  4458. switch (typeof value) {
  4459. case 'undefined':
  4460. return ctx.stylize('undefined', 'undefined');
  4461. case 'string':
  4462. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  4463. .replace(/'/g, "\\'")
  4464. .replace(/\\"/g, '"') + '\'';
  4465. return ctx.stylize(simple, 'string');
  4466. case 'number':
  4467. if (value === 0 && (1/value) === -Infinity) {
  4468. return ctx.stylize('-0', 'number');
  4469. }
  4470. return ctx.stylize('' + value, 'number');
  4471. case 'boolean':
  4472. return ctx.stylize('' + value, 'boolean');
  4473. }
  4474. // For some reason typeof null is "object", so special case here.
  4475. if (value === null) {
  4476. return ctx.stylize('null', 'null');
  4477. }
  4478. }
  4479. function formatError(value) {
  4480. return '[' + Error.prototype.toString.call(value) + ']';
  4481. }
  4482. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  4483. var output = [];
  4484. for (var i = 0, l = value.length; i < l; ++i) {
  4485. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  4486. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4487. String(i), true));
  4488. } else {
  4489. output.push('');
  4490. }
  4491. }
  4492. keys.forEach(function(key) {
  4493. if (!key.match(/^\d+$/)) {
  4494. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4495. key, true));
  4496. }
  4497. });
  4498. return output;
  4499. }
  4500. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  4501. var name, str;
  4502. if (value.__lookupGetter__) {
  4503. if (value.__lookupGetter__(key)) {
  4504. if (value.__lookupSetter__(key)) {
  4505. str = ctx.stylize('[Getter/Setter]', 'special');
  4506. } else {
  4507. str = ctx.stylize('[Getter]', 'special');
  4508. }
  4509. } else {
  4510. if (value.__lookupSetter__(key)) {
  4511. str = ctx.stylize('[Setter]', 'special');
  4512. }
  4513. }
  4514. }
  4515. if (visibleKeys.indexOf(key) < 0) {
  4516. name = '[' + key + ']';
  4517. }
  4518. if (!str) {
  4519. if (ctx.seen.indexOf(value[key]) < 0) {
  4520. if (recurseTimes === null) {
  4521. str = formatValue(ctx, value[key], null);
  4522. } else {
  4523. str = formatValue(ctx, value[key], recurseTimes - 1);
  4524. }
  4525. if (str.indexOf('\n') > -1) {
  4526. if (array) {
  4527. str = str.split('\n').map(function(line) {
  4528. return ' ' + line;
  4529. }).join('\n').substr(2);
  4530. } else {
  4531. str = '\n' + str.split('\n').map(function(line) {
  4532. return ' ' + line;
  4533. }).join('\n');
  4534. }
  4535. }
  4536. } else {
  4537. str = ctx.stylize('[Circular]', 'special');
  4538. }
  4539. }
  4540. if (typeof name === 'undefined') {
  4541. if (array && key.match(/^\d+$/)) {
  4542. return str;
  4543. }
  4544. name = JSON.stringify('' + key);
  4545. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  4546. name = name.substr(1, name.length - 2);
  4547. name = ctx.stylize(name, 'name');
  4548. } else {
  4549. name = name.replace(/'/g, "\\'")
  4550. .replace(/\\"/g, '"')
  4551. .replace(/(^"|"$)/g, "'");
  4552. name = ctx.stylize(name, 'string');
  4553. }
  4554. }
  4555. return name + ': ' + str;
  4556. }
  4557. function reduceToSingleString(output, base, braces) {
  4558. var numLinesEst = 0;
  4559. var length = output.reduce(function(prev, cur) {
  4560. numLinesEst++;
  4561. if (cur.indexOf('\n') >= 0) numLinesEst++;
  4562. return prev + cur.length + 1;
  4563. }, 0);
  4564. if (length > 60) {
  4565. return braces[0] +
  4566. (base === '' ? '' : base + '\n ') +
  4567. ' ' +
  4568. output.join(',\n ') +
  4569. ' ' +
  4570. braces[1];
  4571. }
  4572. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  4573. }
  4574. function isArray(ar) {
  4575. return Array.isArray(ar) ||
  4576. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  4577. }
  4578. function isRegExp(re) {
  4579. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  4580. }
  4581. function isDate(d) {
  4582. return typeof d === 'object' && objectToString(d) === '[object Date]';
  4583. }
  4584. function isError(e) {
  4585. return typeof e === 'object' && objectToString(e) === '[object Error]';
  4586. }
  4587. function objectToString(o) {
  4588. return Object.prototype.toString.call(o);
  4589. }
  4590. },{"./getEnumerableProperties":15,"./getName":17,"./getProperties":20}],24:[function(require,module,exports){
  4591. /*!
  4592. * Chai - flag utility
  4593. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4594. * MIT Licensed
  4595. */
  4596. /*!
  4597. * Module dependancies
  4598. */
  4599. var inspect = require('./inspect');
  4600. var config = require('../config');
  4601. /**
  4602. * ### .objDisplay (object)
  4603. *
  4604. * Determines if an object or an array matches
  4605. * criteria to be inspected in-line for error
  4606. * messages or should be truncated.
  4607. *
  4608. * @param {Mixed} javascript object to inspect
  4609. * @name objDisplay
  4610. * @namespace Utils
  4611. * @api public
  4612. */
  4613. module.exports = function (obj) {
  4614. var str = inspect(obj)
  4615. , type = Object.prototype.toString.call(obj);
  4616. if (config.truncateThreshold && str.length >= config.truncateThreshold) {
  4617. if (type === '[object Function]') {
  4618. return !obj.name || obj.name === ''
  4619. ? '[Function]'
  4620. : '[Function: ' + obj.name + ']';
  4621. } else if (type === '[object Array]') {
  4622. return '[ Array(' + obj.length + ') ]';
  4623. } else if (type === '[object Object]') {
  4624. var keys = Object.keys(obj)
  4625. , kstr = keys.length > 2
  4626. ? keys.splice(0, 2).join(', ') + ', ...'
  4627. : keys.join(', ');
  4628. return '{ Object (' + kstr + ') }';
  4629. } else {
  4630. return str;
  4631. }
  4632. } else {
  4633. return str;
  4634. }
  4635. };
  4636. },{"../config":4,"./inspect":23}],25:[function(require,module,exports){
  4637. /*!
  4638. * Chai - overwriteChainableMethod utility
  4639. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4640. * MIT Licensed
  4641. */
  4642. /**
  4643. * ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
  4644. *
  4645. * Overwites an already existing chainable method
  4646. * and provides access to the previous function or
  4647. * property. Must return functions to be used for
  4648. * name.
  4649. *
  4650. * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
  4651. * function (_super) {
  4652. * }
  4653. * , function (_super) {
  4654. * }
  4655. * );
  4656. *
  4657. * Can also be accessed directly from `chai.Assertion`.
  4658. *
  4659. * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
  4660. *
  4661. * Then can be used as any other assertion.
  4662. *
  4663. * expect(myFoo).to.have.length(3);
  4664. * expect(myFoo).to.have.length.above(3);
  4665. *
  4666. * @param {Object} ctx object whose method / property is to be overwritten
  4667. * @param {String} name of method / property to overwrite
  4668. * @param {Function} method function that returns a function to be used for name
  4669. * @param {Function} chainingBehavior function that returns a function to be used for property
  4670. * @namespace Utils
  4671. * @name overwriteChainableMethod
  4672. * @api public
  4673. */
  4674. module.exports = function (ctx, name, method, chainingBehavior) {
  4675. var chainableBehavior = ctx.__methods[name];
  4676. var _chainingBehavior = chainableBehavior.chainingBehavior;
  4677. chainableBehavior.chainingBehavior = function () {
  4678. var result = chainingBehavior(_chainingBehavior).call(this);
  4679. return result === undefined ? this : result;
  4680. };
  4681. var _method = chainableBehavior.method;
  4682. chainableBehavior.method = function () {
  4683. var result = method(_method).apply(this, arguments);
  4684. return result === undefined ? this : result;
  4685. };
  4686. };
  4687. },{}],26:[function(require,module,exports){
  4688. /*!
  4689. * Chai - overwriteMethod utility
  4690. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4691. * MIT Licensed
  4692. */
  4693. /**
  4694. * ### overwriteMethod (ctx, name, fn)
  4695. *
  4696. * Overwites an already existing method and provides
  4697. * access to previous function. Must return function
  4698. * to be used for name.
  4699. *
  4700. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  4701. * return function (str) {
  4702. * var obj = utils.flag(this, 'object');
  4703. * if (obj instanceof Foo) {
  4704. * new chai.Assertion(obj.value).to.equal(str);
  4705. * } else {
  4706. * _super.apply(this, arguments);
  4707. * }
  4708. * }
  4709. * });
  4710. *
  4711. * Can also be accessed directly from `chai.Assertion`.
  4712. *
  4713. * chai.Assertion.overwriteMethod('foo', fn);
  4714. *
  4715. * Then can be used as any other assertion.
  4716. *
  4717. * expect(myFoo).to.equal('bar');
  4718. *
  4719. * @param {Object} ctx object whose method is to be overwritten
  4720. * @param {String} name of method to overwrite
  4721. * @param {Function} method function that returns a function to be used for name
  4722. * @namespace Utils
  4723. * @name overwriteMethod
  4724. * @api public
  4725. */
  4726. module.exports = function (ctx, name, method) {
  4727. var _method = ctx[name]
  4728. , _super = function () { return this; };
  4729. if (_method && 'function' === typeof _method)
  4730. _super = _method;
  4731. ctx[name] = function () {
  4732. var result = method(_super).apply(this, arguments);
  4733. return result === undefined ? this : result;
  4734. }
  4735. };
  4736. },{}],27:[function(require,module,exports){
  4737. /*!
  4738. * Chai - overwriteProperty utility
  4739. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4740. * MIT Licensed
  4741. */
  4742. /**
  4743. * ### overwriteProperty (ctx, name, fn)
  4744. *
  4745. * Overwites an already existing property getter and provides
  4746. * access to previous value. Must return function to use as getter.
  4747. *
  4748. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  4749. * return function () {
  4750. * var obj = utils.flag(this, 'object');
  4751. * if (obj instanceof Foo) {
  4752. * new chai.Assertion(obj.name).to.equal('bar');
  4753. * } else {
  4754. * _super.call(this);
  4755. * }
  4756. * }
  4757. * });
  4758. *
  4759. *
  4760. * Can also be accessed directly from `chai.Assertion`.
  4761. *
  4762. * chai.Assertion.overwriteProperty('foo', fn);
  4763. *
  4764. * Then can be used as any other assertion.
  4765. *
  4766. * expect(myFoo).to.be.ok;
  4767. *
  4768. * @param {Object} ctx object whose property is to be overwritten
  4769. * @param {String} name of property to overwrite
  4770. * @param {Function} getter function that returns a getter function to be used for name
  4771. * @namespace Utils
  4772. * @name overwriteProperty
  4773. * @api public
  4774. */
  4775. module.exports = function (ctx, name, getter) {
  4776. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  4777. , _super = function () {};
  4778. if (_get && 'function' === typeof _get.get)
  4779. _super = _get.get
  4780. Object.defineProperty(ctx, name,
  4781. { get: function () {
  4782. var result = getter(_super).call(this);
  4783. return result === undefined ? this : result;
  4784. }
  4785. , configurable: true
  4786. });
  4787. };
  4788. },{}],28:[function(require,module,exports){
  4789. /*!
  4790. * Chai - test utility
  4791. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4792. * MIT Licensed
  4793. */
  4794. /*!
  4795. * Module dependancies
  4796. */
  4797. var flag = require('./flag');
  4798. /**
  4799. * # test(object, expression)
  4800. *
  4801. * Test and object for expression.
  4802. *
  4803. * @param {Object} object (constructed Assertion)
  4804. * @param {Arguments} chai.Assertion.prototype.assert arguments
  4805. * @namespace Utils
  4806. * @name test
  4807. */
  4808. module.exports = function (obj, args) {
  4809. var negate = flag(obj, 'negate')
  4810. , expr = args[0];
  4811. return negate ? !expr : expr;
  4812. };
  4813. },{"./flag":13}],29:[function(require,module,exports){
  4814. /*!
  4815. * Chai - transferFlags utility
  4816. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4817. * MIT Licensed
  4818. */
  4819. /**
  4820. * ### transferFlags(assertion, object, includeAll = true)
  4821. *
  4822. * Transfer all the flags for `assertion` to `object`. If
  4823. * `includeAll` is set to `false`, then the base Chai
  4824. * assertion flags (namely `object`, `ssfi`, and `message`)
  4825. * will not be transferred.
  4826. *
  4827. *
  4828. * var newAssertion = new Assertion();
  4829. * utils.transferFlags(assertion, newAssertion);
  4830. *
  4831. * var anotherAsseriton = new Assertion(myObj);
  4832. * utils.transferFlags(assertion, anotherAssertion, false);
  4833. *
  4834. * @param {Assertion} assertion the assertion to transfer the flags from
  4835. * @param {Object} object the object to transfer the flags to; usually a new assertion
  4836. * @param {Boolean} includeAll
  4837. * @namespace Utils
  4838. * @name transferFlags
  4839. * @api private
  4840. */
  4841. module.exports = function (assertion, object, includeAll) {
  4842. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  4843. if (!object.__flags) {
  4844. object.__flags = Object.create(null);
  4845. }
  4846. includeAll = arguments.length === 3 ? includeAll : true;
  4847. for (var flag in flags) {
  4848. if (includeAll ||
  4849. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  4850. object.__flags[flag] = flags[flag];
  4851. }
  4852. }
  4853. };
  4854. },{}],30:[function(require,module,exports){
  4855. /*!
  4856. * assertion-error
  4857. * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
  4858. * MIT Licensed
  4859. */
  4860. /*!
  4861. * Return a function that will copy properties from
  4862. * one object to another excluding any originally
  4863. * listed. Returned function will create a new `{}`.
  4864. *
  4865. * @param {String} excluded properties ...
  4866. * @return {Function}
  4867. */
  4868. function exclude () {
  4869. var excludes = [].slice.call(arguments);
  4870. function excludeProps (res, obj) {
  4871. Object.keys(obj).forEach(function (key) {
  4872. if (!~excludes.indexOf(key)) res[key] = obj[key];
  4873. });
  4874. }
  4875. return function extendExclude () {
  4876. var args = [].slice.call(arguments)
  4877. , i = 0
  4878. , res = {};
  4879. for (; i < args.length; i++) {
  4880. excludeProps(res, args[i]);
  4881. }
  4882. return res;
  4883. };
  4884. };
  4885. /*!
  4886. * Primary Exports
  4887. */
  4888. module.exports = AssertionError;
  4889. /**
  4890. * ### AssertionError
  4891. *
  4892. * An extension of the JavaScript `Error` constructor for
  4893. * assertion and validation scenarios.
  4894. *
  4895. * @param {String} message
  4896. * @param {Object} properties to include (optional)
  4897. * @param {callee} start stack function (optional)
  4898. */
  4899. function AssertionError (message, _props, ssf) {
  4900. var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
  4901. , props = extend(_props || {});
  4902. // default values
  4903. this.message = message || 'Unspecified AssertionError';
  4904. this.showDiff = false;
  4905. // copy from properties
  4906. for (var key in props) {
  4907. this[key] = props[key];
  4908. }
  4909. // capture stack trace
  4910. ssf = ssf || arguments.callee;
  4911. if (ssf && Error.captureStackTrace) {
  4912. Error.captureStackTrace(this, ssf);
  4913. } else {
  4914. this.stack = new Error().stack;
  4915. }
  4916. }
  4917. /*!
  4918. * Inherit from Error.prototype
  4919. */
  4920. AssertionError.prototype = Object.create(Error.prototype);
  4921. /*!
  4922. * Statically set name
  4923. */
  4924. AssertionError.prototype.name = 'AssertionError';
  4925. /*!
  4926. * Ensure correct constructor
  4927. */
  4928. AssertionError.prototype.constructor = AssertionError;
  4929. /**
  4930. * Allow errors to be converted to JSON for static transfer.
  4931. *
  4932. * @param {Boolean} include stack (default: `true`)
  4933. * @return {Object} object that can be `JSON.stringify`
  4934. */
  4935. AssertionError.prototype.toJSON = function (stack) {
  4936. var extend = exclude('constructor', 'toJSON', 'stack')
  4937. , props = extend({ name: this.name }, this);
  4938. // include stack if exists and not turned off
  4939. if (false !== stack && this.stack) {
  4940. props.stack = this.stack;
  4941. }
  4942. return props;
  4943. };
  4944. },{}],31:[function(require,module,exports){
  4945. module.exports = require('./lib/eql');
  4946. },{"./lib/eql":32}],32:[function(require,module,exports){
  4947. /*!
  4948. * deep-eql
  4949. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  4950. * MIT Licensed
  4951. */
  4952. /*!
  4953. * Module dependencies
  4954. */
  4955. var type = require('type-detect');
  4956. /*!
  4957. * Buffer.isBuffer browser shim
  4958. */
  4959. var Buffer;
  4960. try { Buffer = require('buffer').Buffer; }
  4961. catch(ex) {
  4962. Buffer = {};
  4963. Buffer.isBuffer = function() { return false; }
  4964. }
  4965. /*!
  4966. * Primary Export
  4967. */
  4968. module.exports = deepEqual;
  4969. /**
  4970. * Assert super-strict (egal) equality between
  4971. * two objects of any type.
  4972. *
  4973. * @param {Mixed} a
  4974. * @param {Mixed} b
  4975. * @param {Array} memoised (optional)
  4976. * @return {Boolean} equal match
  4977. */
  4978. function deepEqual(a, b, m) {
  4979. if (sameValue(a, b)) {
  4980. return true;
  4981. } else if ('date' === type(a)) {
  4982. return dateEqual(a, b);
  4983. } else if ('regexp' === type(a)) {
  4984. return regexpEqual(a, b);
  4985. } else if (Buffer.isBuffer(a)) {
  4986. return bufferEqual(a, b);
  4987. } else if ('arguments' === type(a)) {
  4988. return argumentsEqual(a, b, m);
  4989. } else if (!typeEqual(a, b)) {
  4990. return false;
  4991. } else if (('object' !== type(a) && 'object' !== type(b))
  4992. && ('array' !== type(a) && 'array' !== type(b))) {
  4993. return sameValue(a, b);
  4994. } else {
  4995. return objectEqual(a, b, m);
  4996. }
  4997. }
  4998. /*!
  4999. * Strict (egal) equality test. Ensures that NaN always
  5000. * equals NaN and `-0` does not equal `+0`.
  5001. *
  5002. * @param {Mixed} a
  5003. * @param {Mixed} b
  5004. * @return {Boolean} equal match
  5005. */
  5006. function sameValue(a, b) {
  5007. if (a === b) return a !== 0 || 1 / a === 1 / b;
  5008. return a !== a && b !== b;
  5009. }
  5010. /*!
  5011. * Compare the types of two given objects and
  5012. * return if they are equal. Note that an Array
  5013. * has a type of `array` (not `object`) and arguments
  5014. * have a type of `arguments` (not `array`/`object`).
  5015. *
  5016. * @param {Mixed} a
  5017. * @param {Mixed} b
  5018. * @return {Boolean} result
  5019. */
  5020. function typeEqual(a, b) {
  5021. return type(a) === type(b);
  5022. }
  5023. /*!
  5024. * Compare two Date objects by asserting that
  5025. * the time values are equal using `saveValue`.
  5026. *
  5027. * @param {Date} a
  5028. * @param {Date} b
  5029. * @return {Boolean} result
  5030. */
  5031. function dateEqual(a, b) {
  5032. if ('date' !== type(b)) return false;
  5033. return sameValue(a.getTime(), b.getTime());
  5034. }
  5035. /*!
  5036. * Compare two regular expressions by converting them
  5037. * to string and checking for `sameValue`.
  5038. *
  5039. * @param {RegExp} a
  5040. * @param {RegExp} b
  5041. * @return {Boolean} result
  5042. */
  5043. function regexpEqual(a, b) {
  5044. if ('regexp' !== type(b)) return false;
  5045. return sameValue(a.toString(), b.toString());
  5046. }
  5047. /*!
  5048. * Assert deep equality of two `arguments` objects.
  5049. * Unfortunately, these must be sliced to arrays
  5050. * prior to test to ensure no bad behavior.
  5051. *
  5052. * @param {Arguments} a
  5053. * @param {Arguments} b
  5054. * @param {Array} memoize (optional)
  5055. * @return {Boolean} result
  5056. */
  5057. function argumentsEqual(a, b, m) {
  5058. if ('arguments' !== type(b)) return false;
  5059. a = [].slice.call(a);
  5060. b = [].slice.call(b);
  5061. return deepEqual(a, b, m);
  5062. }
  5063. /*!
  5064. * Get enumerable properties of a given object.
  5065. *
  5066. * @param {Object} a
  5067. * @return {Array} property names
  5068. */
  5069. function enumerable(a) {
  5070. var res = [];
  5071. for (var key in a) res.push(key);
  5072. return res;
  5073. }
  5074. /*!
  5075. * Simple equality for flat iterable objects
  5076. * such as Arrays or Node.js buffers.
  5077. *
  5078. * @param {Iterable} a
  5079. * @param {Iterable} b
  5080. * @return {Boolean} result
  5081. */
  5082. function iterableEqual(a, b) {
  5083. if (a.length !== b.length) return false;
  5084. var i = 0;
  5085. var match = true;
  5086. for (; i < a.length; i++) {
  5087. if (a[i] !== b[i]) {
  5088. match = false;
  5089. break;
  5090. }
  5091. }
  5092. return match;
  5093. }
  5094. /*!
  5095. * Extension to `iterableEqual` specifically
  5096. * for Node.js Buffers.
  5097. *
  5098. * @param {Buffer} a
  5099. * @param {Mixed} b
  5100. * @return {Boolean} result
  5101. */
  5102. function bufferEqual(a, b) {
  5103. if (!Buffer.isBuffer(b)) return false;
  5104. return iterableEqual(a, b);
  5105. }
  5106. /*!
  5107. * Block for `objectEqual` ensuring non-existing
  5108. * values don't get in.
  5109. *
  5110. * @param {Mixed} object
  5111. * @return {Boolean} result
  5112. */
  5113. function isValue(a) {
  5114. return a !== null && a !== undefined;
  5115. }
  5116. /*!
  5117. * Recursively check the equality of two objects.
  5118. * Once basic sameness has been established it will
  5119. * defer to `deepEqual` for each enumerable key
  5120. * in the object.
  5121. *
  5122. * @param {Mixed} a
  5123. * @param {Mixed} b
  5124. * @return {Boolean} result
  5125. */
  5126. function objectEqual(a, b, m) {
  5127. if (!isValue(a) || !isValue(b)) {
  5128. return false;
  5129. }
  5130. if (a.prototype !== b.prototype) {
  5131. return false;
  5132. }
  5133. var i;
  5134. if (m) {
  5135. for (i = 0; i < m.length; i++) {
  5136. if ((m[i][0] === a && m[i][1] === b)
  5137. || (m[i][0] === b && m[i][1] === a)) {
  5138. return true;
  5139. }
  5140. }
  5141. } else {
  5142. m = [];
  5143. }
  5144. try {
  5145. var ka = enumerable(a);
  5146. var kb = enumerable(b);
  5147. } catch (ex) {
  5148. return false;
  5149. }
  5150. ka.sort();
  5151. kb.sort();
  5152. if (!iterableEqual(ka, kb)) {
  5153. return false;
  5154. }
  5155. m.push([ a, b ]);
  5156. var key;
  5157. for (i = ka.length - 1; i >= 0; i--) {
  5158. key = ka[i];
  5159. if (!deepEqual(a[key], b[key], m)) {
  5160. return false;
  5161. }
  5162. }
  5163. return true;
  5164. }
  5165. },{"buffer":undefined,"type-detect":33}],33:[function(require,module,exports){
  5166. module.exports = require('./lib/type');
  5167. },{"./lib/type":34}],34:[function(require,module,exports){
  5168. /*!
  5169. * type-detect
  5170. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  5171. * MIT Licensed
  5172. */
  5173. /*!
  5174. * Primary Exports
  5175. */
  5176. var exports = module.exports = getType;
  5177. /*!
  5178. * Detectable javascript natives
  5179. */
  5180. var natives = {
  5181. '[object Array]': 'array'
  5182. , '[object RegExp]': 'regexp'
  5183. , '[object Function]': 'function'
  5184. , '[object Arguments]': 'arguments'
  5185. , '[object Date]': 'date'
  5186. };
  5187. /**
  5188. * ### typeOf (obj)
  5189. *
  5190. * Use several different techniques to determine
  5191. * the type of object being tested.
  5192. *
  5193. *
  5194. * @param {Mixed} object
  5195. * @return {String} object type
  5196. * @api public
  5197. */
  5198. function getType (obj) {
  5199. var str = Object.prototype.toString.call(obj);
  5200. if (natives[str]) return natives[str];
  5201. if (obj === null) return 'null';
  5202. if (obj === undefined) return 'undefined';
  5203. if (obj === Object(obj)) return 'object';
  5204. return typeof obj;
  5205. }
  5206. exports.Library = Library;
  5207. /**
  5208. * ### Library
  5209. *
  5210. * Create a repository for custom type detection.
  5211. *
  5212. * ```js
  5213. * var lib = new type.Library;
  5214. * ```
  5215. *
  5216. */
  5217. function Library () {
  5218. this.tests = {};
  5219. }
  5220. /**
  5221. * #### .of (obj)
  5222. *
  5223. * Expose replacement `typeof` detection to the library.
  5224. *
  5225. * ```js
  5226. * if ('string' === lib.of('hello world')) {
  5227. * // ...
  5228. * }
  5229. * ```
  5230. *
  5231. * @param {Mixed} object to test
  5232. * @return {String} type
  5233. */
  5234. Library.prototype.of = getType;
  5235. /**
  5236. * #### .define (type, test)
  5237. *
  5238. * Add a test to for the `.test()` assertion.
  5239. *
  5240. * Can be defined as a regular expression:
  5241. *
  5242. * ```js
  5243. * lib.define('int', /^[0-9]+$/);
  5244. * ```
  5245. *
  5246. * ... or as a function:
  5247. *
  5248. * ```js
  5249. * lib.define('bln', function (obj) {
  5250. * if ('boolean' === lib.of(obj)) return true;
  5251. * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
  5252. * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
  5253. * return !! ~blns.indexOf(obj);
  5254. * });
  5255. * ```
  5256. *
  5257. * @param {String} type
  5258. * @param {RegExp|Function} test
  5259. * @api public
  5260. */
  5261. Library.prototype.define = function (type, test) {
  5262. if (arguments.length === 1) return this.tests[type];
  5263. this.tests[type] = test;
  5264. return this;
  5265. };
  5266. /**
  5267. * #### .test (obj, test)
  5268. *
  5269. * Assert that an object is of type. Will first
  5270. * check natives, and if that does not pass it will
  5271. * use the user defined custom tests.
  5272. *
  5273. * ```js
  5274. * assert(lib.test('1', 'int'));
  5275. * assert(lib.test('yes', 'bln'));
  5276. * ```
  5277. *
  5278. * @param {Mixed} object
  5279. * @param {String} type
  5280. * @return {Boolean} result
  5281. * @api public
  5282. */
  5283. Library.prototype.test = function (obj, type) {
  5284. if (type === getType(obj)) return true;
  5285. var test = this.tests[type];
  5286. if (test && 'regexp' === getType(test)) {
  5287. return test.test(obj);
  5288. } else if (test && 'function' === getType(test)) {
  5289. return test(obj);
  5290. } else {
  5291. throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
  5292. }
  5293. };
  5294. },{}],35:[function(require,module,exports){
  5295. arguments[4][33][0].apply(exports,arguments)
  5296. },{"./lib/type":36,"dup":33}],36:[function(require,module,exports){
  5297. /*!
  5298. * type-detect
  5299. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  5300. * MIT Licensed
  5301. */
  5302. /*!
  5303. * Primary Exports
  5304. */
  5305. var exports = module.exports = getType;
  5306. /**
  5307. * ### typeOf (obj)
  5308. *
  5309. * Use several different techniques to determine
  5310. * the type of object being tested.
  5311. *
  5312. *
  5313. * @param {Mixed} object
  5314. * @return {String} object type
  5315. * @api public
  5316. */
  5317. var objectTypeRegexp = /^\[object (.*)\]$/;
  5318. function getType(obj) {
  5319. var type = Object.prototype.toString.call(obj).match(objectTypeRegexp)[1].toLowerCase();
  5320. // Let "new String('')" return 'object'
  5321. if (typeof Promise === 'function' && obj instanceof Promise) return 'promise';
  5322. // PhantomJS has type "DOMWindow" for null
  5323. if (obj === null) return 'null';
  5324. // PhantomJS has type "DOMWindow" for undefined
  5325. if (obj === undefined) return 'undefined';
  5326. return type;
  5327. }
  5328. exports.Library = Library;
  5329. /**
  5330. * ### Library
  5331. *
  5332. * Create a repository for custom type detection.
  5333. *
  5334. * ```js
  5335. * var lib = new type.Library;
  5336. * ```
  5337. *
  5338. */
  5339. function Library() {
  5340. if (!(this instanceof Library)) return new Library();
  5341. this.tests = {};
  5342. }
  5343. /**
  5344. * #### .of (obj)
  5345. *
  5346. * Expose replacement `typeof` detection to the library.
  5347. *
  5348. * ```js
  5349. * if ('string' === lib.of('hello world')) {
  5350. * // ...
  5351. * }
  5352. * ```
  5353. *
  5354. * @param {Mixed} object to test
  5355. * @return {String} type
  5356. */
  5357. Library.prototype.of = getType;
  5358. /**
  5359. * #### .define (type, test)
  5360. *
  5361. * Add a test to for the `.test()` assertion.
  5362. *
  5363. * Can be defined as a regular expression:
  5364. *
  5365. * ```js
  5366. * lib.define('int', /^[0-9]+$/);
  5367. * ```
  5368. *
  5369. * ... or as a function:
  5370. *
  5371. * ```js
  5372. * lib.define('bln', function (obj) {
  5373. * if ('boolean' === lib.of(obj)) return true;
  5374. * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
  5375. * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
  5376. * return !! ~blns.indexOf(obj);
  5377. * });
  5378. * ```
  5379. *
  5380. * @param {String} type
  5381. * @param {RegExp|Function} test
  5382. * @api public
  5383. */
  5384. Library.prototype.define = function(type, test) {
  5385. if (arguments.length === 1) return this.tests[type];
  5386. this.tests[type] = test;
  5387. return this;
  5388. };
  5389. /**
  5390. * #### .test (obj, test)
  5391. *
  5392. * Assert that an object is of type. Will first
  5393. * check natives, and if that does not pass it will
  5394. * use the user defined custom tests.
  5395. *
  5396. * ```js
  5397. * assert(lib.test('1', 'int'));
  5398. * assert(lib.test('yes', 'bln'));
  5399. * ```
  5400. *
  5401. * @param {Mixed} object
  5402. * @param {String} type
  5403. * @return {Boolean} result
  5404. * @api public
  5405. */
  5406. Library.prototype.test = function(obj, type) {
  5407. if (type === getType(obj)) return true;
  5408. var test = this.tests[type];
  5409. if (test && 'regexp' === getType(test)) {
  5410. return test.test(obj);
  5411. } else if (test && 'function' === getType(test)) {
  5412. return test(obj);
  5413. } else {
  5414. throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
  5415. }
  5416. };
  5417. },{}]},{},[1])(1)
  5418. });