Socket
Socket
Sign inDemoInstall

chai

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai - npm Package Compare versions

Comparing version 0.5.3 to 1.0.0

lib/browser/error.js

172

History.md
1.0.0 / 2012-05-15
==================
* readme cleanup
* browser build
* utility comments
* removed docs
* update to package.json
* docs build
* comments / docs updates
* plugins app cleanup
* Merge pull request #61 from joliss/doc
* Fix and improve documentation of assert.equal and friends
* browser build
* doc checkpoint - texture
* Update chai-jquery link
* Use defined return value of Assertion extension functions
* Update utility docs
1.0.0-rc3 / 2012-05-09
==================
* Merge branch 'feature/rc3'
* docs update
* browser build
* assert test conformity for minor refactor api
* assert minor refactor
* update util tests for new add/overwrite prop/method format
* added chai.Assertion.add/overwrite prop/method for plugin toolbox
* add/overwrite prop/method don't make assumptions about context
* doc test suite
* docs don't need coverage
* refactor all simple chains into one forEach loop, for clean documentation
* updated npm ignore
* remove old docs
* docs checkpoint - guide styled
* Merge pull request #59 from joliss/doc
* Document how to run the test suite
* don't need to rebuild docs to view
* dep update
* docs checkpoint - api section
* comment updates for docs
* new doc site checkpoint - plugin directory!
* Merge pull request #57 from kossnocorp/patch-1
* Fix typo: devDependancies → devDependencies
* Using message flag in `getMessage` util instead of old `msg` property.
* Adding self to package.json contributors.
* `getMessage` shouldn't choke on null/omitted messages.
* `return this` not necessary in example.
* `return this` not necessary in example.
* Sinon–Chai has a dash
* updated plugins list for docs
1.0.0-rc2 / 2012-05-06
==================
* Merge branch 'feature/test-cov'
* browser build
* missing assert tests for ownProperty
* appropriate assert equivalent for expect.to.have.property(key, val)
* reset AssertionError to include full stack
* test for plugin utilities
* overwrite Property and Method now ensure chain
* version notes in readme
1.0.0-rc1 / 2012-05-04
==================
* browser build (rc1)
* assert match/notMatch tests
* assert interface - notMatch, ownProperty, notOwnProperty, ownPropertyVal, ownPropertyNotVal
* cleaner should interface export.
* added chai.Assertion.prototype._obj (getter) for quick access to object flag
* moved almostEqual / almostDeepEqual to stats plugin
* added mocha.opts
* Add test for `utils.addMethod`
* Fix a typo
* Add test for `utils.overwriteMethod`
* Fix a typo
* Browser build
* Add undefined assertion
* Add null assertion
* Fix an issue with `mocha --watch`
* travis no longer tests on node 0.4.x
* removing unnecissary carbon dep
* Merge branch 'feature/plugins-app'
* docs build
* templates for docs express app for plugin directory
* express app for plugin and static serving
* added web server deps
* Merge pull request #54 from josher19/master
* Remove old test.assert code
* Use util.inspect instead of inspect for deepAlmostEqual and almostEqual
* browser build
* Added almostEqual and deepAlmostEqual to assert test suite.
* bug - context determinants for utils
* dec=0 means rounding, so assert.deepAlmostEqual({pi: 3.1416}, {pi: 3}, 0) is true
* wrong travis link
* readme updates for version information
* travis tests 0.5.x branch as well
* [bug] util `addProperty` not correctly exporting
* read me version notes
* browser build 1.0.0alpha1
* not using reserved words in internal assertions. #52
* version tick
* clean up redundant tests
* Merge branch 'refs/heads/0.6.x'
* update version tag in package 1.0.0alpha1
* browser build
* added utility tests to browser specs
* beginning utility testing
* updated utility comments
* utility - overwriteMethod
* utility - overwriteProperty
* utility - addMethod
* utility - addProperty
* missing ;
* contributors list update
* Merge branch 'refs/heads/0.6.x-docs' into 0.6.x
* Added guide link to docs. WIP
* Include/contain are now both properties and methods
* Add an alias annotation
* Remove usless function wrapper
* Fix a typo
* A/an are now both properties and methods
* [docs] new site homepage layout / color checkpoint
* Ignore IE-specific error properties.
* Fixing order of error message test.
* New cross-browser `getName` util.
* Fixing up `AssertionError` inheritance.
* backup docs
* Add doctypes
* [bug] was still using `constructor.name` in `throw` assertion
* [bug] flag Object.create(null) instead of new Object
* [test] browser build
* [refactor] all usage of Assertion.prototype.assert now uses template tags and flags
* [refactor] remove Assertion.prototype.inspect for testable object inspection
* [refactor] object to test is now stored in flag, with ssfi and custom message
* [bug] flag util - don't return on `set`
* [docs] comments for getMessage utility
* [feature] getMessage
* [feature] testing utilities
* [refactor] flag doesn't require `call`
* Make order of source files well-defined
* Added support for throw(errorInstance).
* Use a foolproof method of grabbing an error's name.
* Removed constructor.name check from throw.
* disabled stackTrack configuration tests until api is stable again
* first version of line displayed error for node js (unstable)
* refactor core Assertion to use flag utility for negation
* added flag utility
* tests for assert interface negatives. Closed #42
* added assertion negatives that were missing. #42
* Support for expected and actual parameters in assert-style error object
* chai as promised - readme
* Added assert.fail. Closes #40
* better error message for assert.operator. Closes #39
* [refactor] Assertion#property to use getPathValue property
* added getPathValue utility helper
* removed todo about browser build
* version notes
* version bumb 0.6.0
* browser build
* [refactor] browser compile function to replace with `require('./error')' with 'require('./browser/error')'
* [feature] browser uses different error.js
* [refactor] error without chai.fail
* Assertion & interfaces use new utils helper export
* [refactor] primary export for new plugin util usage
* added util index.js helper
* added 2012 to copyright headers
* Added DeepEqual assertions
0.5.3 / 2012-04-21

@@ -3,0 +175,0 @@ ==================

825

lib/assertion.js
/*!
* chai
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
* http://chaijs.com
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*
* Primarily a refactor of: should.js
* https://github.com/visionmedia/should.js
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
/**
* ### BDD Style Introduction
*
* The BDD style is exposed through `expect` or `should` interfaces. In both
* scenarios, you chain together natural language assertions.
*
* // expect
* var expect = require('chai').expect;
* expect(foo).to.equal('bar');
*
* // should
* var should = require('chai').should();
* foo.should.equal('bar');
*
* #### Differences
*
* The `expect` interface provides a function as a starting point for chaining
* your language assertions. It works on node.js and in all browsers.
*
* The `should` interface extends `Object.prototype` to provide a single getter as
* the starting point for your language assertions. It works on node.js and in
* all browsers except Internet Explorer.
*
* #### Configuration
*
* By default, Chai does not show stack traces upon an AssertionError. This can
* be changed by modifying the `includeStack` parameter for chai.Assertion. For example:
*
* var chai = require('chai');
* chai.Assertion.includeStack = true; // defaults to false
*/

@@ -49,5 +14,5 @@ /*!

var AssertionError = require('./error')
, eql = require('./utils/eql')
, toString = Object.prototype.toString
, inspect = require('./utils/inspect');
, util = require('./utils')
, flag = util.flag;

@@ -62,3 +27,3 @@ /*!

/*!
* # Assertion Constructor
* Assertion Constructor
*

@@ -71,10 +36,9 @@ * Creates object for chaining.

function Assertion (obj, msg, stack) {
this.ssfi = stack || arguments.callee;
this.obj = obj;
this.msg = msg;
flag(this, 'ssfi', stack || arguments.callee);
flag(this, 'object', obj);
flag(this, 'message', msg);
}
/*!
* ## Assertion.includeStack
* , toString = Object.prototype.toString
* ### Assertion.includeStack
*

@@ -92,4 +56,20 @@ * User configurable property, influences whether stack trace

Assertion.addProperty = function (name, fn) {
util.addProperty(this.prototype, name, fn);
};
Assertion.addMethod = function (name, fn) {
util.addMethod(this.prototype, name, fn);
};
Assertion.overwriteProperty = function (name, fn) {
util.overwriteProperty(this.prototype, name, fn);
};
Assertion.overwriteMethod = function (name, fn) {
util.overwriteMethod(this.prototype, name, fn);
};
/*!
* # .assert(expression, message, negateMessage, expected, actual)
* ### .assert(expression, message, negateMessage, expected, actual)
*

@@ -102,18 +82,18 @@ * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.

* @param {String} negatedMessage to display if negated expression fails
* @param {*} expected value (remember to check for negation)
* @param {*} actual (optional) will default to `this.obj`
* @param {Mixed} expected value (remember to check for negation)
* @param {Mixed} actual (optional) will default to `this.obj`
* @api private
*/
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, actual) {
actual = actual || this.obj;
var msg = (this.negate ? negateMsg : msg)
, ok = this.negate ? !expr : expr;
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual) {
var msg = util.getMessage(this, arguments)
, actual = util.getActual(this, arguments)
, ok = util.test(this, arguments);
if (!ok) {
throw new AssertionError({
message: this.msg ? this.msg + ': ' + msg : msg // include custom message if available
message: msg
, actual: actual
, expected: expected
, stackStartFunction: (Assertion.includeStack) ? this.assert : this.ssfi
, stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
});

@@ -124,62 +104,69 @@ }

/*!
* # inspect
*
* Returns the current object stringified.
* ### ._obj
*
* @name inspect
* Quick reference to stored `actual` value for plugin developers.
*
* @api private
*/
Object.defineProperty(Assertion.prototype, 'inspect',
Object.defineProperty(Assertion.prototype, '_obj',
{ get: function () {
return inspect(this.obj);
return flag(this, 'object');
}
, configurable: true
, set: function (val) {
flag(this, 'object', val);
}
});
/**
* # to
* ### Language Chains
*
* Language chain.
* The following are provide as chainable getters to
* improve the readability of your assertions. They
* do not provide an testing capability unless they
* have been overwritten by a plugin.
*
* @name to
* @api public
*/
Object.defineProperty(Assertion.prototype, 'to',
{ get: function () {
return this;
}
, configurable: true
});
/**
* # be
* **Chains**
*
* Language chain.
* - to
* - be
* - been
* - is
* - and
* - have
* - with
*
* @name be
* @name language chains
* @api public
*/
Object.defineProperty(Assertion.prototype, 'be',
{ get: function () {
return this;
}
, configurable: true
[ 'to', 'be', 'been'
, 'is', 'and', 'have'
, 'with' ].forEach(function (chain) {
Object.defineProperty(Assertion.prototype, chain,
{ get: function () {
return this;
}
, configurable: true
});
});
/**
* # been
* ### .not
*
* Language chain. Also tests `tense` to past for addon
* modules that use the tense feature.
* Negates any of assertions following in the chain.
*
* @name been
* expect(foo).to.not.equal('bar');
* expect(goodFn).to.not.throw(Error);
* expect({ foo: 'baz' }).to.have.property('foo')
* .and.not.equal('bar');
*
* @name not
* @api public
*/
Object.defineProperty(Assertion.prototype, 'been',
Object.defineProperty(Assertion.prototype, 'not',
{ get: function () {
this.tense = 'past';
flag(this, 'negate', true);
return this;

@@ -191,29 +178,48 @@ }

/**
* # an
* ### .a(type)
*
* Language chain.
* The `a` and `an` assertions are aliases that can be
* used either as property languague chains or to assert
* typeof.
*
* @name an
* // typeof
* expect('test').to.be.a('string');
* expect({ foo: 'bar' }).to.be.an('object');
*
* // language chain
* expect(foo).to.be.an.instanceof(Foo);
*
* @name a
* @alias an
* @param {String} type
* @api public
*/
var an = function () {
var assert = function(type) {
var obj = flag(this, 'object')
, klass = type.charAt(0).toUpperCase() + type.slice(1);
this.assert(
'[object ' + klass + ']' === toString.call(obj)
, 'expected #{this} to be a ' + type
, 'expected #{this} not to be a ' + type
, '[object ' + klass + ']'
, toString.call(obj)
);
return this;
};
assert.__proto__ = this;
return assert;
};
Object.defineProperty(Assertion.prototype, 'an',
{ get: function () {
return this;
}
{ get: an
, configurable: true
});
/**
* # is
*
* Language chain.
*
* @name is
* @api public
*/
Object.defineProperty(Assertion.prototype, 'is',
{ get: function () {
return this;
}
Object.defineProperty(Assertion.prototype, 'a',
{ get: an
, configurable: true

@@ -223,30 +229,43 @@ });

/**
* # and
* ### .include(value)
*
* Language chain.
* The `include` and `contain` assertions can be used as either a property
* based language chain or as a method to assert the inclusion of an object
* in an Array or substring in string. When used as a property langugae chain,
* it toggles the `contain` flag for the `keys` assertion.
*
* @name and
* expect([1,2,3]).to.include(2);
* expect('foobar').to.contain('foo');
* expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
*
* @name include
* @alias contain
* @param {Object|String|Number} obj
* @api public
*/
Object.defineProperty(Assertion.prototype, 'and',
{ get: function () {
return this;
}
var include = function () {
flag(this, 'contains', true);
var assert = function(val) {
var obj = flag(this, 'object')
this.assert(
~obj.indexOf(val)
, 'expected #{this} to include ' + util.inspect(val)
, 'expected #{this} to not include ' + util.inspect(val));
return this;
};
assert.__proto__ = this;
return assert;
};
Object.defineProperty(Assertion.prototype, 'contain',
{ get: include
, configurable: true
});
/**
* # have
*
* Language chain.
*
* @name have
* @api public
*/
Object.defineProperty(Assertion.prototype, 'have',
{ get: function () {
return this;
}
Object.defineProperty(Assertion.prototype, 'include',
{ get: include
, configurable: true

@@ -256,12 +275,23 @@ });

/**
* # with
* ### .ok
*
* Language chain.
* Assert object truthiness.
*
* @name with
* expect('everthing').to.be.ok;
* expect(1).to.be.ok;
* expect(false).to.not.be.ok;
* expect(undefined).to.not.be.ok;
* expect(null).to.not.be.ok;
*
* @name ok
* @api public
*/
Object.defineProperty(Assertion.prototype, 'with',
Object.defineProperty(Assertion.prototype, 'ok',
{ get: function () {
this.assert(
flag(this, 'object')
, 'expected #{this} to be truthy'
, 'expected #{this} to be falsy');
return this;

@@ -273,13 +303,22 @@ }

/**
* # .not
* ### .true
*
* Negates any of assertions following in the chain.
* Assert object is true
*
* @name not
* expect(true).to.be.true;
* expect(1).to.not.be.true;
*
* @name true
* @api public
*/
Object.defineProperty(Assertion.prototype, 'not',
Object.defineProperty(Assertion.prototype, 'true',
{ get: function () {
this.negate = true;
this.assert(
true === flag(this, 'object')
, 'expected #{this} to be true'
, 'expected #{this} to be false'
, this.negate ? false : true
);
return this;

@@ -291,21 +330,21 @@ }

/**
* # .ok
* ### .false
*
* Assert object truthiness.
* Assert object is false
*
* expect('everthing').to.be.ok;
* expect(false).to.not.be.ok;
* expect(undefined).to.not.be.ok;
* expect(null).to.not.be.ok;
* expect(false).to.be.false;
* expect(0).to.not.be.false;
*
* @name ok
* @name false
* @api public
*/
Object.defineProperty(Assertion.prototype, 'ok',
Object.defineProperty(Assertion.prototype, 'false',
{ get: function () {
this.assert(
this.obj
, 'expected ' + this.inspect + ' to be truthy'
, 'expected ' + this.inspect + ' to be falsy');
false === flag(this, 'object')
, 'expected #{this} to be false'
, 'expected #{this} to be true'
, this.negate ? true : false
);

@@ -318,16 +357,19 @@ return this;

/**
* # .true
* ### .null
*
* Assert object is true
* Assert object is null
*
* @name true
* expect(null).to.be.null;
* expect(undefined).not.to.be.null;
*
* @name null
* @api public
*/
Object.defineProperty(Assertion.prototype, 'true',
Object.defineProperty(Assertion.prototype, 'null',
{ get: function () {
this.assert(
true === this.obj
, 'expected ' + this.inspect + ' to be true'
, 'expected ' + this.inspect + ' to be false'
null === flag(this, 'object')
, 'expected #{this} to be null'
, 'expected #{this} not to be null'
, this.negate ? false : true

@@ -342,17 +384,20 @@ );

/**
* # .false
* ### .undefined
*
* Assert object is false
* Assert object is undefined
*
* @name false
* expect(undefined).to.be.undefined;
* expect(null).to.not.be.undefined;
*
* @name undefined
* @api public
*/
Object.defineProperty(Assertion.prototype, 'false',
Object.defineProperty(Assertion.prototype, 'undefined',
{ get: function () {
this.assert(
false === this.obj
, 'expected ' + this.inspect + ' to be false'
, 'expected ' + this.inspect + ' to be true'
, this.negate ? true : false
undefined === flag(this, 'object')
, 'expected #{this} to be undefined'
, 'expected #{this} not to be undefined'
, this.negate ? false : true
);

@@ -366,11 +411,12 @@

/**
* # .exist
* ### .exist
*
* Assert object exists (null).
*
* var foo = 'hi'
* , bar;
* expect(foo).to.exist;
* expect(bar).to.not.exist;
* var foo = 'hi'
* , bar;
*
* expect(foo).to.exist;
* expect(bar).to.not.exist;
*
* @name exist

@@ -383,5 +429,5 @@ * @api public

this.assert(
null != this.obj
, 'expected ' + this.inspect + ' to exist'
, 'expected ' + this.inspect + ' to not exist'
null != flag(this, 'object')
, 'expected #{this} to exist'
, 'expected #{this} to not exist'
);

@@ -395,7 +441,11 @@

/**
* # .empty
* ### .empty
*
* Assert object's length to be 0.
* Assert object's length to be `0`. For arrays, it check
* the length property. For objects it gets the count of
* enumerable keys.
*
* expect([]).to.be.empty;
* expect([]).to.be.empty;
* expect('').to.be.empty;
* expect({}).to.be.empty;
*

@@ -408,8 +458,9 @@ * @name empty

{ get: function () {
var expected = this.obj;
var obj = flag(this, 'object')
, expected = obj;
if (Array.isArray(this.obj)) {
expected = this.obj.length;
} else if (typeof this.obj === 'object') {
expected = Object.keys(this.obj).length;
if (Array.isArray(obj) || 'string' === typeof object) {
expected = obj.length;
} else if (typeof obj === 'object') {
expected = Object.keys(obj).length;
}

@@ -419,4 +470,4 @@

!expected
, 'expected ' + this.inspect + ' to be empty'
, 'expected ' + this.inspect + ' not to be empty');
, 'expected #{this} to be empty'
, 'expected #{this} not to be empty');

@@ -429,9 +480,9 @@ return this;

/**
* # .arguments
* ### .arguments
*
* Assert object is an instanceof arguments.
*
* function test () {
* expect(arguments).to.be.arguments;
* }
* function test () {
* expect(arguments).to.be.arguments;
* }
*

@@ -444,8 +495,9 @@ * @name arguments

{ get: function () {
var obj = flag(this, 'object');
this.assert(
'[object Arguments]' == Object.prototype.toString.call(this.obj)
, 'expected ' + this.inspect + ' to be arguments'
, 'expected ' + this.inspect + ' to not be arguments'
'[object Arguments]' == Object.prototype.toString.call(obj)
, 'expected #{this} to be arguments'
, 'expected #{this} to not be arguments'
, '[object Arguments]'
, Object.prototype.toString.call(this.obj)
, Object.prototype.toString.call(obj)
);

@@ -459,10 +511,12 @@

/**
* # .equal(value)
* ### .equal(value)
*
* Assert strict equality.
* Assert strict equality (===).
*
* expect('hello').to.equal('hello');
* expect('hello').to.equal('hello');
* expect(42).to.equal(42);
* expect(1).to.not.equal(true);
*
* @name equal
* @param {*} value
* @param {Mixed} value
* @api public

@@ -473,5 +527,5 @@ */

this.assert(
val === this.obj
, 'expected ' + this.inspect + ' to equal ' + inspect(val)
, 'expected ' + this.inspect + ' to not equal ' + inspect(val)
val === flag(this, 'object')
, 'expected #{this} to equal #{exp}'
, 'expected #{this} to not equal #{exp}'
, val );

@@ -483,7 +537,8 @@

/**
* # .eql(value)
* ### .eql(value)
*
* Assert deep equality.
*
* expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
* expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
* expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
*

@@ -497,5 +552,5 @@ * @name eql

this.assert(
eql(obj, this.obj)
, 'expected ' + this.inspect + ' to equal ' + inspect(obj)
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj)
util.eql(obj, flag(this, 'object'))
, 'expected #{this} to equal #{exp}'
, 'expected #{this} to not equal #{exp}'
, obj );

@@ -507,9 +562,10 @@

/**
* # .above(value)
* ### .above(value)
*
* Assert greater than `value`.
*
* expect(10).to.be.above(5);
* expect(10).to.be.above(5);
*
* @name above
* @alias gt
* @param {Number} value

@@ -521,5 +577,5 @@ * @api public

this.assert(
this.obj > val
, 'expected ' + this.inspect + ' to be above ' + val
, 'expected ' + this.inspect + ' to be below ' + val);
flag(this, 'object') > val
, 'expected #{this} to be above ' + val
, 'expected #{this} to be below ' + val);

@@ -530,9 +586,10 @@ return this;

/**
* # .below(value)
* ### .below(value)
*
* Assert less than `value`.
*
* expect(5).to.be.below(10);
* expect(5).to.be.below(10);
*
* @name below
* @alias lt
* @param {Number} value

@@ -544,5 +601,5 @@ * @api public

this.assert(
this.obj < val
, 'expected ' + this.inspect + ' to be below ' + val
, 'expected ' + this.inspect + ' to be above ' + val);
flag(this, 'object') < val
, 'expected #{this} to be below ' + val
, 'expected #{this} to be above ' + val);

@@ -553,7 +610,7 @@ return this;

/**
* # .within(start, finish)
* ### .within(start, finish)
*
* Assert that a number is within a range.
*
* expect(7).to.be.within(5,10);
* expect(7).to.be.within(5,10);
*

@@ -567,8 +624,9 @@ * @name within

Assertion.prototype.within = function (start, finish) {
var range = start + '..' + finish;
var obj = flag(this, 'object')
, range = start + '..' + finish;
this.assert(
this.obj >= start && this.obj <= finish
, 'expected ' + this.inspect + ' to be within ' + range
, 'expected ' + this.inspect + ' to not be within ' + range);
obj >= start && obj <= finish
, 'expected #{this} to be within ' + range
, 'expected #{this} to not be within ' + range);

@@ -579,38 +637,13 @@ return this;

/**
* # .a(type)
* ### .instanceof(constructor)
*
* Assert typeof.
*
* expect('test').to.be.a('string');
*
* @name a
* @param {String} type
* @api public
*/
Assertion.prototype.a = function (type) {
var klass = type.charAt(0).toUpperCase() + type.slice(1);
this.assert(
'[object ' + klass + ']' === toString.call(this.obj)
, 'expected ' + this.inspect + ' to be a ' + type
, 'expected ' + this.inspect + ' not to be a ' + type
, '[object ' + klass + ']'
, toString.call(this.obj)
);
return this;
};
/**
* # .instanceof(constructor)
*
* Assert instanceof.
*
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
*
* expect(Chai).to.be.an.instanceOf(Tea);
* expect(Chai).to.be.an.instanceof(Tea);
* expect([ 1, 2, 3 ]).to.be.instanceof(Array);
*
* @name instanceOf
* @name instanceof
* @param {Constructor}

@@ -622,7 +655,7 @@ * @alias instanceOf

Assertion.prototype.instanceOf = function (constructor) {
var name = constructor.name;
var name = util.getName(constructor);
this.assert(
this.obj instanceof constructor
, 'expected ' + this.inspect + ' to be an instance of ' + name
, 'expected ' + this.inspect + ' to not be an instance of ' + name);
flag(this, 'object') instanceof constructor
, 'expected #{this} to be an instance of ' + name
, 'expected #{this} to not be an instance of ' + name);

@@ -633,14 +666,26 @@ return this;

/**
* # .property(name, [value])
* ### .property(name, [value])
*
* Assert that property of `name` exists, optionally with `value`.
* Can use dot-notation for deep reference.
*
* var obj = { foo: 'bar' }
* expect(obj).to.have.property('foo');
* expect(obj).to.have.property('foo', 'bar');
* expect(obj).to.have.property('foo').to.be.a('string');
* // legacy / simple referencing
* var obj = { foo: 'bar' }
* expect(obj).to.have.property('foo');
* expect(obj).to.have.property('foo', 'bar');
* expect(obj).to.have.property('foo').to.be.a('string');
*
* // deep referencing
* var deepObj = {
* green: { tea: 'matcha' }
* , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
* };
* expect(deepObj).to.have.property('green.tea', 'matcha');
* expect(deepObj).to.have.property('teas[1]', 'matcha');
* expect(deepObj).to.have.property('teas[2].tea', 'konacha');
*
* @name property
* @param {String} name
* @param {*} value (optional)
* @param {Mixed} value (optional)
* @returns value of property for chaining

@@ -651,11 +696,15 @@ * @api public

Assertion.prototype.property = function (name, val) {
if (this.negate && undefined !== val) {
if (undefined === this.obj[name]) {
throw new Error(this.inspect + ' has no property ' + inspect(name));
var obj = flag(this, 'object')
, value = util.getPathValue(name, obj)
, negate = flag(this, 'negate');
if (negate && undefined !== val) {
if (undefined === value) {
throw new Error(util.inspect(obj) + ' has no property ' + util.inspect(name));
}
} else {
this.assert(
undefined !== this.obj[name]
, 'expected ' + this.inspect + ' to have a property ' + inspect(name)
, 'expected ' + this.inspect + ' to not have property ' + inspect(name));
undefined !== value
, 'expected #{this} to have a property ' + util.inspect(name)
, 'expected #{this} to not have property ' + util.inspect(name));
}

@@ -665,12 +714,11 @@

this.assert(
val === this.obj[name]
, 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
inspect(val) + ', but got ' + inspect(this.obj[name])
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val)
val === value
, 'expected #{this} to have a property ' + util.inspect(name) + ' of #{exp}, but got #{act}'
, 'expected #{this} to not have a property ' + util.inspect(name) + ' of #{act}'
, val
, this.obj[val]
, value
);
}
this.obj = this.obj[name];
flag(this, 'object', value);
return this;

@@ -680,7 +728,7 @@ };

/**
* # .ownProperty(name)
* ### .ownProperty(name)
*
* Assert that has own property by `name`.
*
* expect('test').to.have.ownProperty('length');
* expect('test').to.have.ownProperty('length');
*

@@ -694,6 +742,7 @@ * @name ownProperty

Assertion.prototype.ownProperty = function (name) {
var obj = flag(this, 'object');
this.assert(
this.obj.hasOwnProperty(name)
, 'expected ' + this.inspect + ' to have own property ' + inspect(name)
, 'expected ' + this.inspect + ' to not have own property ' + inspect(name));
obj.hasOwnProperty(name)
, 'expected #{this} to have own property ' + util.inspect(name)
, 'expected #{this} to not have own property ' + util.inspect(name));
return this;

@@ -703,8 +752,8 @@ };

/**
* # .length(val)
* ### .length(val)
*
* Assert that object has expected length.
*
* expect([1,2,3]).to.have.length(3);
* expect('foobar').to.have.length(6);
* expect([1,2,3]).to.have.length(3);
* expect('foobar').to.have.length(6);
*

@@ -718,9 +767,10 @@ * @name length

Assertion.prototype.length = function (n) {
new Assertion(this.obj).to.have.property('length');
var len = this.obj.length;
var obj = flag(this, 'object');
new Assertion(obj).to.have.property('length');
var len = obj.length;
this.assert(
len == n
, 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
, 'expected ' + this.inspect + ' to not have a length of ' + len
, 'expected #{this} to have a length of #{exp} but got #{act}'
, 'expected #{this} to not have a length of #{act}'
, n

@@ -734,7 +784,7 @@ , len

/**
* # .match(regexp)
* ### .match(regexp)
*
* Assert that matches regular expression.
*
* expect('foobar').to.match(/^foo/);
* expect('foobar').to.match(/^foo/);
*

@@ -747,6 +797,7 @@ * @name match

Assertion.prototype.match = function (re) {
var obj = flag(this, 'object');
this.assert(
re.exec(this.obj)
, 'expected ' + this.inspect + ' to match ' + re
, 'expected ' + this.inspect + ' not to match ' + re);
re.exec(obj)
, 'expected #{this} to match ' + re
, 'expected #{this} not to match ' + re);

@@ -756,29 +807,9 @@ return this;

/**
* # .include(obj)
*
* Assert the inclusion of an object in an Array or substring in string.
*
* expect([1,2,3]).to.include(2);
*
* @name include
* @param {Object|String|Number} obj
* @api public
*/
Assertion.prototype.include = function (obj) {
this.assert(
~this.obj.indexOf(obj)
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));
return this;
};
/**
* # .string(string)
* ### .string(string)
*
* Assert inclusion of string in string.
*
* expect('foobar').to.have.string('bar');
* expect('foobar').to.have.string('bar');
*

@@ -791,8 +822,9 @@ * @name string

Assertion.prototype.string = function (str) {
new Assertion(this.obj).is.a('string');
var obj = flag(this, 'object');
new Assertion(obj).is.a('string');
this.assert(
~this.obj.indexOf(str)
, 'expected ' + this.inspect + ' to contain ' + inspect(str)
, 'expected ' + this.inspect + ' to not contain ' + inspect(str));
~obj.indexOf(str)
, 'expected #{this} to contain ' + util.inspect(str)
, 'expected #{this} to not contain ' + util.inspect(str));

@@ -802,29 +834,11 @@ return this;

/**
* # contain
* ### .keys(key1, [key2], [...])
*
* Toggles the `contain` flag for the `keys` assertion.
* Assert exact keys or the inclusing of keys
* using the `include` or `contain` modifier.
*
* @name contain
* @api public
*/
Object.defineProperty(Assertion.prototype, 'contain',
{ get: function () {
this.contains = true;
return this;
},
configurable: true
});
/**
* # .keys(key1, [key2], [...])
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
*
* Assert exact keys or the inclusing of keys using the `contain` modifier.
*
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
*
* @name keys

@@ -837,3 +851,4 @@ * @alias key

Assertion.prototype.keys = function(keys) {
var str
var obj = flag(this, 'object')
, str
, ok = true;

@@ -847,3 +862,3 @@

var actual = Object.keys(this.obj)
var actual = Object.keys(obj)
, len = keys.length;

@@ -857,3 +872,3 @@

// Strict
if (!this.negate && !this.contains) {
if (!flag(this, 'negate') && !flag(this, 'contains')) {
ok = ok && keys.length == actual.length;

@@ -865,3 +880,3 @@ }

keys = keys.map(function(key){
return inspect(key);
return util.inspect(key);
});

@@ -871,3 +886,3 @@ var last = keys.pop();

} else {
str = inspect(keys[0]);
str = util.inspect(keys[0]);
}

@@ -879,3 +894,3 @@

// Have / include
str = (this.contains ? 'contain ' : 'have ') + str;
str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;

@@ -885,6 +900,6 @@ // Assertion

ok
, 'expected ' + this.inspect + ' to ' + str
, 'expected ' + this.inspect + ' to not ' + str
, 'expected #{this} to ' + str
, 'expected #{this} to not ' + str
, keys
, Object.keys(this.obj)
, Object.keys(obj)
);

@@ -896,19 +911,25 @@

/**
* # .throw(constructor)
* ### .throw(constructor)
*
* Assert that a function will throw a specific type of error or that error
* thrown will match a RegExp or include a string.
* Assert that a function will throw a specific type of error, or specific type of error
* (as determined using `instanceof`), optionally with a RegExp or string inclusion test
* for the error's message.
*
* var fn = function () { throw new ReferenceError('This is a bad function.'); }
* expect(fn).to.throw(ReferenceError);
* expect(fn).to.throw(/bad function/);
* expect(fn).to.not.throw('good function');
* expect(fn).to.throw(ReferenceError, /bad function/);
* var err = new ReferenceError('This is a bad function.');
* var fn = function () { throw err; }
* expect(fn).to.throw(ReferenceError);
* expect(fn).to.throw(Error);
* expect(fn).to.throw(/bad function/);
* expect(fn).to.not.throw('good function');
* expect(fn).to.throw(ReferenceError, /bad function/);
* expect(fn).to.throw(err);
* expect(fn).to.not.throw(new RangeError('Out of range.'));
*
* Please note that when a throw expectation is negated, it will check each
* parameter independently, starting with Error constructor type. The appropriate way
* parameter independently, starting with error constructor type. The appropriate way
* to check for the existence of a type of error but for a message that does not match
* is to use `and`.
*
* expect(fn).to.throw(ReferenceError).and.not.throw(/good function/);
* expect(fn).to.throw(ReferenceError)
* .and.not.throw(/good function/);
*

@@ -924,5 +945,8 @@ * @name throw

Assertion.prototype.Throw = function (constructor, msg) {
new Assertion(this.obj).is.a('function');
var obj = flag(this, 'object');
new Assertion(obj).is.a('function');
var thrown = false;
var thrown = false
, desiredError = null
, name = null;

@@ -935,13 +959,30 @@ if (arguments.length === 0) {

constructor = null;
} else if (constructor && constructor instanceof Error) {
desiredError = constructor;
constructor = null;
msg = null;
} else if (typeof constructor === 'function') {
name = (new constructor()).name;
} else {
constructor = null;
}
try {
this.obj();
obj();
} catch (err) {
// first, check constructor
if (constructor && 'function' === typeof constructor) {
// first, check desired error
if (desiredError) {
this.assert(
err instanceof constructor && err.name == constructor.name
, 'expected ' + this.inspect + ' to throw ' + constructor.name + ' but a ' + err.name + ' was thrown'
, 'expected ' + this.inspect + ' to not throw ' + constructor.name );
err === desiredError
, 'expected #{this} to throw ' + util.inspect(desiredError) + ' but ' + util.inspect(err) + ' was thrown'
, 'expected #{this} to not throw ' + util.inspect(desiredError)
);
return this;
}
// next, check constructor
if (constructor) {
this.assert(
err instanceof constructor
, 'expected #{this} to throw ' + name + ' but a ' + err.name + ' was thrown'
, 'expected #{this} to not throw ' + name );
if (!msg) return this;

@@ -953,4 +994,4 @@ }

msg.exec(err.message)
, 'expected ' + this.inspect + ' to throw error matching ' + msg + ' but got ' + inspect(err.message)
, 'expected ' + this.inspect + ' to throw error not matching ' + msg
, 'expected #{this} to throw error matching ' + msg + ' but got ' + util.inspect(err.message)
, 'expected #{this} to throw error not matching ' + msg
);

@@ -961,4 +1002,6 @@ return this;

~err.message.indexOf(msg)
, 'expected ' + this.inspect + ' to throw error including ' + inspect(msg) + ' but got ' + inspect(err.message)
, 'expected ' + this.inspect + ' to throw error not including ' + inspect(msg)
, 'expected #{this} to throw error including #{exp} but got #{act}'
, 'expected #{this} to throw error not including #{act}'
, msg
, err.message
);

@@ -971,8 +1014,8 @@ return this;

var name = (constructor ? constructor.name : 'an error');
var expectedThrown = name ? name : desiredError ? util.inspect(desiredError) : 'an error';
this.assert(
thrown === true
, 'expected ' + this.inspect + ' to throw ' + name
, 'expected ' + this.inspect + ' to not throw ' + name);
, 'expected #{this} to throw ' + expectedThrown
, 'expected #{this} to not throw ' + expectedThrown);

@@ -983,8 +1026,8 @@ return this;

/**
* # .respondTo(method)
* ### .respondTo(method)
*
* Assert that object/class will respond to a method.
*
* expect(Klass).to.respondTo('bar');
* expect(obj).to.respondTo('bar');
* expect(Klass).to.respondTo('bar');
* expect(obj).to.respondTo('bar');
*

@@ -997,10 +1040,11 @@ * @name respondTo

Assertion.prototype.respondTo = function (method) {
var context = ('function' === typeof this.obj)
? this.obj.prototype[method]
: this.obj[method];
var obj = flag(this, 'object')
, context = ('function' === typeof obj)
? obj.prototype[method]
: obj[method];
this.assert(
'function' === typeof context
, 'expected ' + this.inspect + ' to respond to ' + inspect(method)
, 'expected ' + this.inspect + ' to not respond to ' + inspect(method)
, 'expected #{this} to respond to ' + util.inspect(method)
, 'expected #{this} to not respond to ' + util.inspect(method)
, 'function'

@@ -1014,7 +1058,7 @@ , typeof context

/**
* # .satisfy(method)
* ### .satisfy(method)
*
* Assert that passes a truth test.
*
* expect(1).to.satisfy(function(num) { return num > 0; });
* expect(1).to.satisfy(function(num) { return num > 0; });
*

@@ -1027,8 +1071,9 @@ * @name satisfy

Assertion.prototype.satisfy = function (matcher) {
var obj = flag(this, 'object');
this.assert(
matcher(this.obj)
, 'expected ' + this.inspect + ' to satisfy ' + inspect(matcher)
, 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher)
matcher(obj)
, 'expected #{this} to satisfy ' + util.inspect(matcher)
, 'expected #{this} to not satisfy' + util.inspect(matcher)
, this.negate ? false : true
, matcher(this.obj)
, matcher(obj)
);

@@ -1040,7 +1085,7 @@

/**
* # .closeTo(expected, delta)
* ### .closeTo(expected, delta)
*
* Assert that actual is equal to +/- delta.
*
* expect(1.5).to.be.closeTo(1, 0.5);
* expect(1.5).to.be.closeTo(1, 0.5);
*

@@ -1054,6 +1099,7 @@ * @name closeTo

Assertion.prototype.closeTo = function (expected, delta) {
var obj = flag(this, 'object');
this.assert(
(this.obj - delta === expected) || (this.obj + delta === expected)
, 'expected ' + this.inspect + ' to be close to ' + expected + ' +/- ' + delta
, 'expected ' + this.inspect + ' not to be close to ' + expected + ' +/- ' + delta);
(obj - delta === expected) || (obj + delta === expected)
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
, 'expected #{this} not to be close to ' + expected + ' +/- ' + delta);

@@ -1071,2 +1117,5 @@ return this;

})
('equal', 'eq')
('above', 'gt')
('below', 'lt')
('length', 'lengthOf')

@@ -1078,3 +1127,3 @@ ('keys', 'key')

('Throw', 'throws')
('Throw', 'throw') // for troublesome browsers
('Throw', 'throw')
('instanceOf', 'instanceof');

@@ -7,15 +7,42 @@ /*!

var used = [];
var exports = module.exports = {};
var used = []
, exports = module.exports = {};
exports.version = '0.5.3';
/*!
* Chai version
*/
exports.version = '1.0.0';
/*!
* Primary `Assertion` prototype
*/
exports.Assertion = require('./assertion');
/*!
* Assertion Error
*/
exports.AssertionError = require('./error');
exports.inspect = require('./utils/inspect');
/*!
* Utils for plugins (not exported)
*/
var util = require('./utils');
/**
* # .use(function)
*
* Provides a way to extend the internals of Chai
*
* @param {Function}
* @returns {this} for chaining
* @api public
*/
exports.use = function (fn) {
if (!~used.indexOf(fn)) {
fn(this);
fn(this, util);
used.push(fn);

@@ -27,9 +54,21 @@ }

/*!
* Expect interface
*/
var expect = require('./interface/expect');
exports.use(expect);
/*!
* Should interface
*/
var should = require('./interface/should');
exports.use(should);
/*!
* Assert interface
*/
var assert = require('./interface/assert');
exports.use(assert);
/*!
* chai
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
/*!
* Main export
*/
module.exports = AssertionError;
/*!
* Inspired by node.js assert module
* https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
/**
* # AssertionError (constructor)
*
* Create a new assertion error based on the Javascript
* `Error` prototype.
*
* **Options**
* - message
* - actual
* - expected
* - operator
* - startStackFunction
*
* @param {Object} options
* @api public
*/
function AssertionError (options) {
options = options || {};
this.name = 'AssertionError';
this.message = options.message;

@@ -21,11 +37,24 @@ this.actual = options.actual;

if (Error.captureStackTrace) {
Error.captureStackTrace(this, options.stackStartFunction);
if (options.stackStartFunction && Error.captureStackTrace) {
var stackStartFunction = options.stackStartFunction;
Error.captureStackTrace(this, stackStartFunction);
}
}
AssertionError.prototype.__proto__ = Error.prototype;
/*!
* Inherit from Error
*/
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = 'AssertionError';
AssertionError.prototype.constructor = AssertionError;
/**
* # toString()
*
* Override default to string method
*/
AssertionError.prototype.toString = function() {
return this.message;
};
/*!
* chai
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
/**
* ### TDD Style Introduction
*
* The TDD style is exposed through `assert` interfaces. This provides
* the classic assert.`test` notation, similiar to that packaged with
* node.js. This assert module, however, provides several additional
* tests and is browser compatible.
*
* // assert
* var assert = require('chai').assert;
* , foo = 'bar';
*
* assert.typeOf(foo, 'string');
* assert.equal(foo, 'bar');
*
* #### Configuration
*
* By default, Chai does not show stack traces upon an AssertionError. This can
* be changed by modifying the `includeStack` parameter for chai.Assertion. For example:
*
* var chai = require('chai');
* chai.Assertion.includeStack = true; // defaults to false
*/
module.exports = function (chai) {
module.exports = function (chai, util) {
/*!
* Chai dependencies.
*/
var Assertion = chai.Assertion
, inspect = chai.inspect;
, flag = util.flag;

@@ -42,6 +21,24 @@ /*!

var assert = chai.assert = {};
/**
* ### assert(expressions, errorMessage)
*
* Write your own test expressions.
*
* @param {Mixed} expression to test for truthiness.
* @param {String} message to display on error
* @name assert
* @api public
*/
var assert = chai.assert = function (express, errmsg) {
var test = new Assertion(null);
test.assert(
express
, errmsg
, '[ negation message unavailable ]'
);
};
/**
* # .fail(actual, expect, msg, operator)
* ### .fail(actual, expect, msg, operator)
*

@@ -66,6 +63,6 @@ * Throw a failure. Node.js compatible.

});
}
};
/**
* # .ok(object, [message])
* ### .ok(object, [message])
*

@@ -88,5 +85,5 @@ * Assert object is truthy.

/**
* # .equal(actual, expected, [message])
* ### .equal(actual, expected, [message])
*
* Assert strict equality.
* Assert non-strict equality (==).
*

@@ -106,5 +103,5 @@ * assert.equal(3, 3, 'these numbers are equal');

test.assert(
exp == test.obj
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp)
exp == flag(test, 'object')
, 'expected #{this} to equal #{exp}'
, 'expected #{this} to not equal #{act}'
, exp

@@ -116,5 +113,5 @@ , act

/**
* # .notEqual(actual, expected, [message])
* ### .notEqual(actual, expected, [message])
*
* Assert not equal.
* Assert non-strict inequality (!=).
*

@@ -134,5 +131,5 @@ * assert.notEqual(3, 4, 'these numbers are not equal');

test.assert(
exp != test.obj
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp)
exp != flag(test, 'object')
, 'expected #{this} to not equal #{exp}'
, 'expected #{this} to equal #{act}'
, exp

@@ -144,5 +141,5 @@ , act

/**
* # .strictEqual(actual, expected, [message])
* ### .strictEqual(actual, expected, [message])
*
* Assert strict equality.
* Assert strict equality (===).
*

@@ -163,5 +160,5 @@ * assert.strictEqual(true, true, 'these booleans are strictly equal');

/**
* # .notStrictEqual(actual, expected, [message])
* ### .notStrictEqual(actual, expected, [message])
*
* Assert strict equality.
* Assert strict inequality (!==).
*

@@ -182,3 +179,3 @@ * assert.notStrictEqual(1, true, 'these booleans are not strictly equal');

/**
* # .deepEqual(actual, expected, [message])
* ### .deepEqual(actual, expected, [message])
*

@@ -201,3 +198,3 @@ * Assert not deep equality.

/**
* # .notDeepEqual(actual, expected, [message])
* ### .notDeepEqual(actual, expected, [message])
*

@@ -220,3 +217,3 @@ * Assert not deep equality.

/**
* # .isTrue(value, [message])
* ### .isTrue(value, [message])
*

@@ -239,3 +236,3 @@ * Assert `value` is true.

/**
* # .isFalse(value, [message])
* ### .isFalse(value, [message])
*

@@ -258,3 +255,3 @@ * Assert `value` is false.

/**
* # .isNull(value, [message])
* ### .isNull(value, [message])
*

@@ -276,3 +273,3 @@ * Assert `value` is null.

/**
* # .isNotNull(value, [message])
* ### .isNotNull(value, [message])
*

@@ -295,3 +292,3 @@ * Assert `value` is not null.

/**
* # .isUndefined(value, [message])
* ### .isUndefined(value, [message])
*

@@ -313,3 +310,3 @@ * Assert `value` is undefined.

/**
* # .isDefined(value, [message])
* ### .isDefined(value, [message])
*

@@ -332,3 +329,3 @@ * Assert `value` is not undefined.

/**
* # .isFunction(value, [message])
* ### .isFunction(value, [message])
*

@@ -351,4 +348,22 @@ * Assert `value` is a function.

/**
* # .isObject(value, [message])
* ### .isNotFunction(value, [message])
*
* Assert `value` is NOT a function.
*
* var serve_tea = [ 'heat', 'pour', 'sip' ];
* assert.isNotFunction(serve_tea, 'great, we can have tea now');
*
* @name isNotFunction
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotFunction = function (val, msg) {
new Assertion(val, msg).to.not.be.a('function');
};
/**
* ### .isObject(value, [message])
*
* Assert `value` is an object.

@@ -370,4 +385,22 @@ *

/**
* # .isArray(value, [message])
* ### .isNotObject(value, [message])
*
* Assert `value` is NOT an object.
*
* var selection = 'chai'
* assert.isObject(selection, 'tea selection is not an object');
*
* @name isNotObject
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotObject = function (val, msg) {
new Assertion(val, msg).to.not.be.a('object');
};
/**
* ### .isArray(value, [message])
*
* Assert `value` is an instance of Array.

@@ -379,3 +412,3 @@ *

* @name isArray
* @param {*} value
* @param {Mixed} value
* @param {String} message

@@ -390,4 +423,22 @@ * @api public

/**
* # .isString(value, [message])
* ### .isArray(value, [message])
*
* Assert `value` is NOT an instance of Array.
*
* var menu = 'green|chai|oolong';
* assert.isNotArray(menu, 'what kind of tea do we want?');
*
* @name isNotArray
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotArray = function (val, msg) {
new Assertion(val, msg).to.not.be.instanceOf(Array);
};
/**
* ### .isString(value, [message])
*
* Assert `value` is a string.

@@ -409,4 +460,22 @@ *

/**
* # .isNumber(value, [message])
* ### .isNotString(value, [message])
*
* Assert `value` is NOT a string.
*
* var teaorder = 4;
* assert.isNotString(tea_order, 'order placed');
*
* @name isNotString
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotString = function (val, msg) {
new Assertion(val, msg).to.not.be.a('string');
};
/**
* ### .isNumber(value, [message])
*
* Assert `value` is a number

@@ -428,4 +497,22 @@ *

/**
* # .isBoolean(value, [message])
* ### .isNotNumber(value, [message])
*
* Assert `value` NOT is a number
*
* var cups = '2 cups please';
* assert.isNotNumber(cups, 'how many cups');
*
* @name isNotNumber
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotNumber = function (val, msg) {
new Assertion(val, msg).to.not.be.a('number');
};
/**
* ### .isBoolean(value, [message])
*
* Assert `value` is a boolean

@@ -440,3 +527,3 @@ *

* @name isBoolean
* @param {*} value
* @param {Mixed} value
* @param {String} message

@@ -451,4 +538,25 @@ * @api public

/**
* # .typeOf(value, name, [message])
* ### .isNotBoolean(value, [message])
*
* Assert `value` is NOT a boolean
*
* var teaready = 'yep'
* , teaserved = 'nope';
*
* assert.isNotBoolean(tea_ready, 'is the tea ready');
* assert.isNotBoolean(tea_served, 'has tea been served');
*
* @name isNotBoolean
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotBoolean = function (val, msg) {
new Assertion(val, msg).to.not.be.a('boolean');
};
/**
* ### .typeOf(value, name, [message])
*
* Assert typeof `value` is `name`.

@@ -459,3 +567,3 @@ *

* @name typeOf
* @param {*} value
* @param {Mixed} value
* @param {String} typeof name

@@ -471,4 +579,22 @@ * @param {String} message

/**
* # .instanceOf(object, constructor, [message])
* ### .notTypeOf(value, name, [message])
*
* Assert typeof `value` is NOT `name`.
*
* assert.notTypeOf('tea', 'string', 'we have a string');
*
* @name notTypeOf
* @param {Mixed} value
* @param {String} typeof name
* @param {String} message
* @api public
*/
assert.notTypeOf = function (val, type, msg) {
new Assertion(val, msg).to.not.be.a(type);
};
/**
* ### .instanceOf(object, constructor, [message])
*
* Assert `value` is instanceof `constructor`.

@@ -493,4 +619,25 @@ *

/**
* # .include(value, includes, [message])
* ### .notInstanceOf(object, constructor, [message])
*
* Assert `value` is NOT instanceof `constructor`.
*
* var Tea = function (name) { this.name = name; }
* , Chai = new String('chai');
*
* assert.notInstanceOf(Chai, Tea, 'chai is an instance of tea');
*
* @name notInstanceOf
* @param {Object} object
* @param {Constructor} constructor
* @param {String} message
* @api public
*/
assert.notInstanceOf = function (val, type, msg) {
new Assertion(val, msg).to.not.be.instanceOf(type);
};
/**
* ### .include(value, includes, [message])
*
* Assert the inclusion of an object in another. Works

@@ -520,3 +667,3 @@ * for strings and arrays.

/**
* # .match(value, regex, [message])
* ### .match(value, regex, [message])
*

@@ -539,8 +686,101 @@ * Assert that `value` matches regular expression.

/**
* # .length(value, constructor, [message])
* ### .notMatch(value, regex, [message])
*
* Assert that `value` does not match regular expression.
*
* assert.notMatch('foobar', /^foo/, 'Regexp matches');
*
* @name notMatch
* @param {*} value
* @param {RegExp} RegularExpression
* @param {String} message
* @api public
*/
assert.notMatch = function (exp, re, msg) {
new Assertion(exp, msg).to.not.match(re);
};
/**
* ### .property(object, property, [message])
*
* Assert that `object` has property. Can use dot-notation for deep reference.
*
* assert.property({ tea: { green: 'matcha' }}, 'tea.green');
*
* @name property
* @param {Object} object
* @param {String} Property address
* @param {String} message
* @api public
*/
assert.property = function (obj, prop, msg) {
new Assertion(obj, msg).to.have.property(prop);
};
/**
* ### .notOwnProperty(object, property, [message])
*
* Assert that `object` does not have property. Can use dot-notation for deep reference.
*
* assert.ownProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
*
* @name notOwnProperty
* @param {Object} object
* @param {String} property address
* @param {String} message
* @api public
*/
assert.notProperty = function (obj, prop, msg) {
new Assertion(obj, msg).to.not.have.property(prop);
};
/**
* ### .propertyVal(object, property, value, [message])
*
* Assert that `object` has property with `value`.
* Can use dot-notation for deep reference.
*
* assert.propertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
*
* @name propertyVal
* @param {Object} object
* @param {String} property address
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.propertyVal = function (obj, prop, val, msg) {
new Assertion(obj, msg).to.have.property(prop, val);
};
/**
* ### .propertyNotVal(object, property, value, [message])
*
* Assert that `object` has property but `value`
* does not equal `value`. Can use dot-notation for deep reference.
*
* assert.propertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
*
* @name propertyNotVal
* @param {Object} object
* @param {String} property address
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.propertyNotVal = function (obj, prop, val, msg) {
new Assertion(obj, msg).to.not.have.property(prop, val);
};
/**
* ### .lengthOf(object, length, [message])
*
* Assert that object has expected length.
*
* assert.length([1,2,3], 3, 'Array has length of 3');
* assert.length('foobar', 5, 'String has length of 6');
* assert.lengthOf([1,2,3], 3, 'Array has length of 3');
* assert.lengthOf('foobar', 5, 'String has length of 6');
*

@@ -554,3 +794,3 @@ * @name length

assert.length = function (exp, len, msg) {
assert.lengthOf = function (exp, len, msg) {
new Assertion(exp, msg).to.have.length(len);

@@ -560,3 +800,3 @@ };

/**
* # .throws(function, [constructor/regexp], [message])
* ### .throws(function, [constructor/regexp], [message])
*

@@ -587,3 +827,3 @@ * Assert that a function will throw a specific

/**
* # .doesNotThrow(function, [constructor/regexp], [message])
* ### .doesNotThrow(function, [constructor/regexp], [message])
*

@@ -614,3 +854,3 @@ * Assert that a function will throw a specific

/**
* # .operator(val, operator, val2, [message])
* ### .operator(val, operator, val2, [message])
*

@@ -636,5 +876,5 @@ * Compare two values using operator.

test.assert(
true === test.obj
, 'expected ' + inspect(val) + ' to be ' + operator + ' ' + inspect(val2)
, 'expected ' + inspect(val) + ' to not be ' + operator + ' ' + inspect(val2) );
true === flag(test, 'object')
, 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
, 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
};

@@ -658,4 +898,3 @@

})
('length', 'lengthOf')
('throws', 'throw');
};
/*!
* chai
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
module.exports = function (chai) {
module.exports = function (chai, util) {
chai.expect = function (val, message) {

@@ -9,0 +9,0 @@ return new chai.Assertion(val, message);

/*!
* chai
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
module.exports = function (chai) {
module.exports = function (chai, util) {
var Assertion = chai.Assertion;
chai.should = function () {
function loadShould () {
// modify Object.prototype to have `should`
Object.defineProperty(Object.prototype, 'should', {
set: function(){},
get: function(){
if (this instanceof String || this instanceof Number) {
return new Assertion(this.constructor(this));
} else if (this instanceof Boolean) {
return new Assertion(this == true);
Object.defineProperty(Object.prototype, 'should',
{ set: function () {}
, get: function(){
if (this instanceof String || this instanceof Number) {
return new Assertion(this.constructor(this));
} else if (this instanceof Boolean) {
return new Assertion(this == true);
}
return new Assertion(this);
}
return new Assertion(this);
},
configurable: true
, configurable: true
});

@@ -59,2 +59,5 @@

};
chai.should = loadShould;
chai.Should = loadShould;
};
// This is (almost) directly from Node.js utils
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
var getName = require('./getName');
module.exports = inspect;

@@ -48,6 +50,12 @@

// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
// In IE, errors have a single `stack` property, or if they are vanilla `Error`,
// a `stack` plus `description` property; ignore those for consistency.
if (keys.length === 0 || (isError(value) && (
(keys.length === 1 && keys[0] === 'stack') ||
(keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
))) {
if (typeof value === 'function') {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
var name = getName(value);
var nameSuffix = name ? ': ' + name : '';
return ctx.stylize('[Function' + nameSuffix + ']', 'special');
}

@@ -54,0 +62,0 @@ if (isRegExp(value)) {

@@ -5,10 +5,18 @@ {

"description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic.",
"keywords": [ "test", "assertion", "assert", "testing" ],
"version": "0.5.3",
"keywords": [ "test", "assertion", "assert", "testing", "chai" ],
"homepage": "http://chaijs.com",
"license": "MIT",
"contributors": [
"Jake Luer <jake@alogicalparadox.com>",
"Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)",
"Veselin Todorov <hi@vesln.com>",
"John Firebaugh <john.firebaugh@gmail.com>"
],
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/logicalparadox/chai"
"url": "https://github.com/chaijs/chai"
},
"bugs": {
"url": "https://github.com/logicalparadox/chai/issues"
"url": "https://github.com/chaijs/chai/issues"
},

@@ -24,5 +32,4 @@ "main": "./index",

"devDependencies": {
"mocha": "*",
"codex": "0.2.x"
"mocha": "*"
}
}
[![Build Status](https://secure.travis-ci.org/logicalparadox/chai.png)](http://travis-ci.org/logicalparadox/chai)
[![Chai Documentation](https://github.com/logicalparadox/chai/raw/master/docs/template/assets/img/chai-logo.png)](http://chaijs.com)
[![Chai Documentation](http://chaijs.com/public/img/chai-logo.png)](http://chaijs.com)

@@ -8,71 +8,23 @@ Chai is a BDD / TDD assertion library for [node](http://nodejs.org) and the browser that

For more information view the [documentation](http://chaijs.com).
For more information or to download plugins, view the [documentation](http://chaijs.com).
## Installation
### Contributors
Chai is available for both node.js and the browser using any
test framework you like.
commits: 436
files : 41
authors:
325 Jake Luer 74.5%
66 Veselin Todorov 15.1%
12 domenic 2.8%
7 Domenic Denicola 1.6%
5 Juliusz Gonera 1.1%
5 Jo Liss 1.1%
4 josher19 0.9%
4 John Firebaugh 0.9%
3 Jeff Barczewski 0.7%
2 Jakub Nešetřil 0.5%
1 Sasha Koss 0.2%
1 Vinay Pulim 0.2%
1 Anand Patil 0.2%
### Node.js
Package is available through [npm](http://npmjs.org):
npm install chai
Recommend adding it to package.json devDependancies.
### Browser
Include the chai browser build in your testing suite.
<script src="chai.js" type="text/javascript"></script>
Currently supports all modern browsers: IE 9+, Chrome 7+, FireFox 4+, Safari 5+. Want to know if your browser is compatible?
Run the [online test suite](http://chaijs.com/support/tests/).
## Plugins
The Chai community is growing! Plugins allow developers to expand Chai's available
assertions. Here is what the community has come up with so far:
* [chai-spies](https://github.com/logicalparadox/chai-spies) is a basic spy implementation for chai. It's also
a good resource for building chai plugins that work in both node.js and the browser.
* [chai-jquery](https://github.com/jfirebaugh/chai-jquery) by [@jfirebaugh](https://github.com/jfirebaugh)
provides deep jQuery integration with chai's `should` and `expect`.
* [jack](https://github.com/vesln/jack) by [@vesln](https://github.com/vesln) is a mock/stub library that
can be used as a stand-alone or with chai.
* [sinon-chai](https://github.com/domenic/sinon-chai) by [@domenic](https://github.com/domenic) extends chai with
assertions for the Sinon.js mocking framework.
* [chai-as-promised](https://github.com/domenic/chai-as-promised) by [@domenic](https://github.com/domenic) extends
chai with assertions about promises.
## Getting Help
If you have questions or issues, please use this projects
[Github Issues](https://github.com/logicalparadox/chai/issues). You can also keep up to date
on the [Google Group](http://groups.google.com/group/chaijs) or ping [@jakeluer](http://twitter.com/jakeluer)
directly on Twitter. Chai developers can also be found on Freenode IRC in #letstest.js.
## Versions
The current stable version tree is the `0.5.x` tree on the `master` branch. If you are interested in seeing
what we have planned, or if you are a plugin developer interested in preparing your plugins for the
next major release, see the `0.6.x` branch.
- Stable: 0.5.x
- Unstables: 0.6.x
## Contributors
commits: 252
files : 71
authors:
192 Jake Luer 76.2%
53 Veselin Todorov 21.0%
3 Jeff Barczewski 1.2%
1 Vinay Pulim 0.4%
1 Jo Liss 0.4%
1 Domenic Denicola 0.4%
1 John Firebaugh 0.4%
## License

@@ -79,0 +31,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc