Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai

Package Overview
Dependencies
Maintainers
1
Versions
97
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.1.1 to 0.1.2

lib/utils/constants.js

813

chai.js

@@ -0,2 +1,8 @@

!function (name, definition) {
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
else this[name] = definition();
console.log(this);
}('chai', function () {
// CommonJS require()

@@ -91,3 +97,4 @@

, eql = require('./utils/eql')
, inspect = require('./utils/inspect');
, inspect = require('./utils/inspect')
, statusCodes = require('./utils/constants').STATUS_CODES;

@@ -139,3 +146,3 @@ /*!

/*!
* # inpsect
* # inspect
*

@@ -148,4 +155,6 @@ * Returns the current object stringified.

Assertion.prototype.__defineGetter__('inspect', function () {
return inspect(this.obj);
Object.defineProperty(Assertion.prototype, 'inspect',
{ get: function () {
return inspect(this.obj);
}
});

@@ -162,4 +171,6 @@

Assertion.prototype.__defineGetter__('to', function () {
return this;
Object.defineProperty(Assertion.prototype, 'to',
{ get: function () {
return this;
}
});

@@ -176,4 +187,6 @@

Assertion.prototype.__defineGetter__('be', function () {
return this;
Object.defineProperty(Assertion.prototype, 'be',
{ get: function () {
return this;
}
});

@@ -190,6 +203,7 @@

Assertion.prototype.__defineGetter__('an', function () {
return this;
Object.defineProperty(Assertion.prototype, 'an',
{ get: function () {
return this;
}
});
/**

@@ -204,4 +218,6 @@ * # is

Assertion.prototype.__defineGetter__('is', function () {
return this;
Object.defineProperty(Assertion.prototype, 'is',
{ get: function () {
return this;
}
});

@@ -218,4 +234,6 @@

Assertion.prototype.__defineGetter__('and', function () {
return this;
Object.defineProperty(Assertion.prototype, 'and',
{ get: function () {
return this;
}
});

@@ -232,4 +250,6 @@

Assertion.prototype.__defineGetter__('have', function () {
return this;
Object.defineProperty(Assertion.prototype, 'have',
{ get: function () {
return this;
}
});

@@ -246,4 +266,6 @@

Assertion.prototype.__defineGetter__('with', function () {
return this;
Object.defineProperty(Assertion.prototype, 'with',
{ get: function () {
return this;
}
});

@@ -260,5 +282,7 @@

Assertion.prototype.__defineGetter__('not', function () {
this.negate = true;
return this;
Object.defineProperty(Assertion.prototype, 'not',
{ get: function () {
this.negate = true;
return this;
}
});

@@ -280,9 +304,11 @@

Assertion.prototype.__defineGetter__('ok', function () {
this.assert(
this.obj
, 'expected ' + this.inspect + ' to be truthy'
, 'expected ' + this.inspect + ' to be falsey');
Object.defineProperty(Assertion.prototype, 'ok',
{ get: function () {
this.assert(
this.obj
, 'expected ' + this.inspect + ' to be truthy'
, 'expected ' + this.inspect + ' to be falsey');
return this;
return this;
}
});

@@ -299,9 +325,11 @@

Assertion.prototype.__defineGetter__('true', function () {
this.assert(
true === this.obj
, 'expected ' + this.inspect + ' to be true'
, 'expected ' + this.inspect + ' to be false');
Object.defineProperty(Assertion.prototype, 'true',
{ get: function () {
this.assert(
true === this.obj
, 'expected ' + this.inspect + ' to be true'
, 'expected ' + this.inspect + ' to be false');
return this;
return this;
}
});

@@ -318,9 +346,11 @@

Assertion.prototype.__defineGetter__('false', function () {
this.assert(
false === this.obj
, 'expected ' + this.inspect + ' to be false'
, 'expected ' + this.inspect + ' to be true');
Object.defineProperty(Assertion.prototype, 'false',
{ get: function () {
this.assert(
false === this.obj
, 'expected ' + this.inspect + ' to be false'
, 'expected ' + this.inspect + ' to be true');
return this;
return this;
}
});

@@ -342,9 +372,11 @@

Assertion.prototype.__defineGetter__('exist', function () {
this.assert(
null != this.obj
, 'expected ' + this.inspect + ' to exist'
, 'expected ' + this.inspect + ' to not exist');
Object.defineProperty(Assertion.prototype, 'exist',
{ get: function () {
this.assert(
null != this.obj
, 'expected ' + this.inspect + ' to exist'
, 'expected ' + this.inspect + ' to not exist');
return this;
return this;
}
});

@@ -363,11 +395,13 @@

Assertion.prototype.__defineGetter__('empty', function () {
new Assertion(this.obj).to.have.property('length');
Object.defineProperty(Assertion.prototype, 'empty',
{ get: function () {
new Assertion(this.obj).to.have.property('length');
this.assert(
0 === this.obj.length
, 'expected ' + this.inspect + ' to be empty'
, 'expected ' + this.inspect + ' not to be empty');
this.assert(
0 === this.obj.length
, 'expected ' + this.inspect + ' to be empty'
, 'expected ' + this.inspect + ' not to be empty');
return this;
return this;
}
});

@@ -388,9 +422,11 @@

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

@@ -531,5 +567,7 @@

*
* expect(42).to.be.instanceof(Number);
* expect([4,2]).to.be.instanceof(Array);
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
*
* expect(Chai).to.be.an.instanceOf(Tea);
*
* @name instanceOf

@@ -551,24 +589,2 @@ * @param {Constructor}

/**
* # respondTo(method)
*
* Assert that `method` is a function.
*
* var res = { send: function () {} };
* expect(res).to.respondTo('send');
*
* @name respondTo
* @param {String} method name
* @api public
*/
Assertion.prototype.respondTo = function (method) {
this.assert(
'function' == typeof this.obj[method]
, 'expected ' + this.inspect + ' to respond to ' + method + '()'
, 'expected ' + this.inspect + ' to not respond to ' + method + '()');
return this;
}
/**
* # .property(name, [value])

@@ -684,3 +700,3 @@ *

/**
* # .contain(obj)
* # .include(obj)
*

@@ -691,3 +707,3 @@ * Assert the inclusion of an object in an Array

*
* @name contain
* @name include
* @param {Object|String|Number} obj

@@ -697,9 +713,7 @@ * @api public

Assertion.prototype.contain = function (obj) {
new Assertion(this.obj).to.be.an.instanceof(Array);
Assertion.prototype.include = function (obj) {
this.assert(
~this.obj.indexOf(obj)
, 'expected ' + this.inspect + ' to contain ' + inspect(obj)
, 'expected ' + this.inspect + ' to not contain ' + inspect(obj));
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));

@@ -726,4 +740,4 @@ return this;

~this.obj.indexOf(str)
, 'expected ' + this.inspect + ' to include ' + inspect(str)
, 'expected ' + this.inspect + ' to not include ' + inspect(str));
, 'expected ' + this.inspect + ' to contain ' + inspect(str)
, 'expected ' + this.inspect + ' to not contain ' + inspect(str));

@@ -733,47 +747,18 @@ return this;

/**
* # .object(object)
*
* Assert inclusion of object in object.
*
* var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
* expect(obj).to.include.object({foo: 'bar'});
*
* @name object
* @param {Object} object
* @api public
*/
Assertion.prototype.object = function(obj){
new Assertion(this.obj).is.a('object');
var included = true;
for (var key in obj) {
if (obj.hasOwnProperty(key) && !eql(obj[key], this.obj[key])) {
included = false;
break;
}
}
this.assert(
included
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));
return this;
}
/**
* # include
* # contain
*
* Language chain that lags #keys to test for inclusion testing.
* Toggles the `contain` flag for the `keys` assertion.
*
* @name include
* @name contain
* @api public
*/
Assertion.prototype.__defineGetter__('include', function () {
this.includes = true;
return this;
Object.defineProperty(Assertion.prototype, 'contain',
{ get: function () {
this.contains = true;
return this;
}
});

@@ -785,6 +770,6 @@

* Assert exact keys or the inclusing of keys using
* the include modifier.
* the `contain` modifier.
*
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
* expect({ foo: 1, bar: 2, baz: 3 }).to.include.keys('foo', 'bar');
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
*

@@ -816,3 +801,3 @@ * @name keys

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

@@ -836,3 +821,3 @@ }

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

@@ -867,5 +852,3 @@ // Assertion

constructor = constructor || Error;
var name = constructor.name
, thrown = false;
var thrown = false;

@@ -875,10 +858,16 @@ try {

} catch (err) {
thrown = true;
this.assert(
err instanceof constructor
, 'expected ' + this.inspect + ' to throw ' + name
, 'expected ' + this.inspect + ' to not throw ' + name);
return this;
if (constructor) {
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 );
return this;
} else {
thrown = true;
}
}
var name = (constructor ? constructor.name : 'an error');
this.assert(

@@ -888,4 +877,80 @@ thrown === true

, 'expected ' + this.inspect + ' to not throw ' + name);
return this;
};
/**
* # .header(code)
*
* Assert `header` field has expected `value`.
*
* @name header
* @param {String} field
* @param {String} value
* @api public
*/
Assertion.prototype.header = function (field, val) {
new Assertion(this.obj)
.to.have.property('headers').and
.to.have.property(field.toLowerCase(), val);
return this;
}
/**
* # .status(code)
*
* Assert `statusCode` of `code'.
*
* @name json
* @param {Number} code
* @api public
*/
Assertion.prototype.status = function (code) {
new Assertion(this.obj).to.have.property('statusCode');
var status = this.obj.statusCode;
this.assert(
code == status
, 'expected response code of ' + code + ' ' + inspect(statusCodes[code])
+ ', but got ' + status + ' ' + inspect(statusCodes[status])
, 'expected to not respond with ' + code + ' ' + inspect(statusCodes[code]));
}
/**
* # json
*
* Assert that this response has content-type: application/json.
*
* @name json
* @api public
*/
Object.defineProperty(Assertion.prototype, 'json',
{ get: function () {
new Assertion(this.obj).to.have.header('content-type', 'application/json; charset=utf-8');
return this;
}
});
/**
* # html
*
* Assert that this response has content-type: text/html.
*
* @name html
* @api public
*/
Object.defineProperty(Assertion.prototype, 'html',
{ get: function () {
new Assertion(this.obj).to.have.header('content-type', 'text/html; charset=utf-8');
return this;
}
});
/*!

@@ -988,6 +1053,43 @@ * Aliases.

/**
* ### 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');
*/
/*!
* Module dependencies.
*/
var Assertion = require('../assertion');
/*!
* Module export.
*/
var assert = module.exports = {};
/**
* # .ok(object, [message])
*
* Assert object is truthy.
*
* assert.ok('everthing', 'everything is ok');
* assert.ok(false, 'this will fail');
*
* @name ok
* @param {*} object to test
* @param {String} message
* @api public
*/
assert.ok = function (val, msg) {

@@ -997,2 +1099,16 @@ new Assertion(val, msg).is.ok;

/**
* # .equal(actual, expected, [message])
*
* Assert strict equality.
*
* assert.equal(3, 3, 'these numbers are equal');
*
* @name equal
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.equal = function (act, exp, msg) {

@@ -1002,2 +1118,16 @@ new Assertion(act, msg).to.equal(exp);

/**
* # .notEqual(actual, expected, [message])
*
* Assert not strict equality.
*
* assert.notEqual(3, 4, 'these numbers are not equal');
*
* @name notEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.notEqual = function (act, exp, msg) {

@@ -1007,2 +1137,16 @@ new Assertion(act, msg).to.not.equal(exp);

/**
* # .deepEqual(actual, expected, [message])
*
* Assert not deep equality.
*
* assert.deepEqual({ tea: 'green' }, { tea: 'green' });
*
* @name deepEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.deepEqual = function (act, exp, msg) {

@@ -1012,2 +1156,16 @@ new Assertion(act, msg).to.eql(exp);

/**
* # .notDeepEqual(actual, expected, [message])
*
* Assert not deep equality.
*
* assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
*
* @name notDeepEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.notDeepEqual = function (act, exp, msg) {

@@ -1017,2 +1175,16 @@ new Assertion(act, msg).to.not.eql(exp);

/**
* # .isTrue(value, [message])
*
* Assert `value` is true.
*
* var tea_served = true;
* assert.isTrue(tea_served, 'the tea has been served');
*
* @name isTrue
* @param {Boolean} value
* @param {String} message
* @api public
*/
assert.isTrue = function (val, msg) {

@@ -1022,2 +1194,16 @@ new Assertion(val, msg).is.true;

/**
* # .isFalse(value, [message])
*
* Assert `value` is false.
*
* var tea_served = false;
* assert.isFalse(tea_served, 'no tea yet? hmm...');
*
* @name isFalse
* @param {Boolean} value
* @param {String} message
* @api public
*/
assert.isFalse = function (val, msg) {

@@ -1027,2 +1213,15 @@ new Assertion(val, msg).is.false;

/**
* # .isNull(value, [message])
*
* Assert `value` is null.
*
* assert.isNull(err, 'no errors');
*
* @name isNull
* @param {*} value
* @param {String} message
* @api public
*/
assert.isNull = function (val, msg) {

@@ -1032,2 +1231,16 @@ new Assertion(val, msg).to.not.exist;

/**
* # .isNotNull(value, [message])
*
* Assert `value` is not null.
*
* var tea = 'tasty chai';
* assert.isNotNull(tea, 'great, time for tea!');
*
* @name isNotNull
* @param {*} value
* @param {String} message
* @api public
*/
assert.isNotNull = function (val, msg) {

@@ -1037,2 +1250,15 @@ new Assertion(val, msg).to.exist;

/**
* # .isUndefined(value, [message])
*
* Assert `value` is undefined.
*
* assert.isUndefined(tea, 'no tea defined');
*
* @name isUndefined
* @param {*} value
* @param {String} message
* @api public
*/
assert.isUndefined = function (val, msg) {

@@ -1042,5 +1268,15 @@ new Assertion(val, msg).to.equal(undefined);

assert.isNan = function (val, msg) {
new Assertion(val, msg).to.not.equal(val);
};
/**
* # .isFunction(value, [message])
*
* Assert `value` is a function.
*
* var serve_tea = function () { return 'cup of tea'; };
* assert.isFunction(serve_tea, 'great, we can have tea now');
*
* @name isFunction
* @param {Function} value
* @param {String} message
* @api public
*/

@@ -1051,2 +1287,16 @@ assert.isFunction = function (val, msg) {

/**
* # .isObject(value, [message])
*
* Assert `value` is an object.
*
* var selection = { name: 'Chai', serve: 'with spices' };
* assert.isObject(selection, 'tea selection is an object');
*
* @name isObject
* @param {Object} value
* @param {String} message
* @api public
*/
assert.isObject = function (val, msg) {

@@ -1056,5 +1306,15 @@ new Assertion(val, msg).to.be.an('object');

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

@@ -1065,2 +1325,34 @@ assert.isArray = function (val, msg) {

/**
* # .isString(value, [message])
*
* Assert `value` is a string.
*
* var teaorder = 'chai';
* assert.isString(tea_order, 'order placed');
*
* @name isString
* @param {String} value
* @param {String} message
* @api public
*/
assert.isString = function (val, msg) {
new Assertion(val, msg).to.be.a('string');
};
/**
* # .isNumber(value, [message])
*
* Assert `value` is a number
*
* var cups = 2;
* assert.isNumber(cups, 'how many cups');
*
* @name isNumber
* @param {Number} value
* @param {String} message
* @api public
*/
assert.isNumber = function (val, msg) {

@@ -1070,2 +1362,19 @@ new Assertion(val, msg).to.be.instanceof(Number);

/**
* # .isBoolean(value, [message])
*
* Assert `value` is a boolean
*
* var teaready = true
* , teaserved = false;
*
* assert.isBoolean(tea_ready, 'is the tea ready');
* assert.isBoolean(tea_served, 'has tea been served');
*
* @name isBoolean
* @param {*} value
* @param {String} message
* @api public
*/
assert.isBoolean = function (val, msg) {

@@ -1075,2 +1384,16 @@ new Assertion(val, msg).to.be.a('boolean');

/**
* # .typeOf(value, name, [message])
*
* Assert typeof `value` is `name`.
*
* assert.typeOf('tea', 'string', 'we have a string');
*
* @name typeOf
* @param {*} value
* @param {String} typeof name
* @param {String} message
* @api public
*/
assert.typeOf = function (val, type, msg) {

@@ -1080,2 +1403,19 @@ new Assertion(val, msg).to.be.a(type);

/**
* # .instanceOf(object, constructor, [message])
*
* Assert `value` is instanceof `constructor`.
*
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
*
* assert.instanceOf(Chai, Tea, 'chai is an instance of tea');
*
* @name instanceOf
* @param {Object} object
* @param {Constructor} constructor
* @param {String} message
* @api public
*/
assert.instanceOf = function (val, type, msg) {

@@ -1085,6 +1425,46 @@ new Assertion(val, msg).to.be.instanceof(type);

/**
* # .include(value, includes, [message])
*
* Assert the inclusion of an object in another.
*
* var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
* assert.include(obj, {foo: 'bar'}, 'object contains subobject');
*
* assert.include('foobar', 'bar', 'foobar contains string `var`);
* assert.include([ 1, 2, 3], 3, 'array contains value);
*
* @name include
* @param {Array|String|Object} value
* @param {*} includes
* @param {String} message
* @api public
*/
assert.include = function (exp, inc, msg) {
new Assertion(exp, msg).to.include(inc);
var obj = new Assertion(exp, msg);
if (Array.isArray(exp)) {
obj.to.contain(inc);
} else if ('string' === typeof exp) {
obj.to.include.string(inc);
} else {
obj.to.include.object(inc);
}
};
/**
* # .match(value, constructor, [message])
*
* Assert that `value` matches regular expression.
*
* assert.match('foobar', /^foo/, 'Regexp matches');
*
* @name match
* @param {*} value
* @param {RegExp} RegularExpression
* @param {String} message
* @api public
*/
assert.match = function (exp, re, msg) {

@@ -1094,2 +1474,17 @@ new Assertion(exp, msg).to.match(re);

/**
* # .length(value, constructor, [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');
*
* @name length
* @param {*} value
* @param {Number} length
* @param {String} message
* @api public
*/
assert.length = function (exp, len, msg) {

@@ -1099,5 +1494,38 @@ new Assertion(exp, msg).to.have.length(len);

assert.throws = function (fn, type, msg) {
/**
* # .throw(function, constructor, [message])
*
* Assert that a function will throw a specific
* type of error.
*
* var fn = function () { throw new ReferenceError(''); }
* assert.throw(fn, ReferenceError, 'function throw reference error');
*
* @name throw
* @alias throws
* @param {Function} function to test
* @param {ErrorConstructor} constructor
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @api public
*/
assert.throw = function (fn, type, msg) {
new Assertions(fn, msg).to.throw(type);
};
/*!
* Aliases.
*/
(function alias(name, as){
assert[as] = assert[name];
return alias;
})
('length', 'lengthOf');
//('keys', 'key')
//('ownProperty', 'haveOwnProperty')
//('above', 'greaterThan')
//('below', 'lessThan')
//('throw', 'throws');
}); // module: interface/assert.js

@@ -1155,2 +1583,17 @@

should.throw = function (fn, err) {
new Assertion(fn).to.throw(err);
};
// negation
should.not = {}
should.not.equal = function (val1, val2) {
new Assertion(val).to.not.equal(val2);
};
should.not.throw = function (fn, err) {
new Assertion(fn).to.not.throw(err);
};
return should;

@@ -1160,2 +1603,67 @@ };

require.register("utils/constants.js", function(module, exports, require){
var exports = module.exports = {};
/**
* More includes from node.js code
* https://github.com/joyent/node/blob/master/lib/http.js
*/
exports.STATUS_CODES = {
100 : 'Continue',
101 : 'Switching Protocols',
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
200 : 'OK',
201 : 'Created',
202 : 'Accepted',
203 : 'Non-Authoritative Information',
204 : 'No Content',
205 : 'Reset Content',
206 : 'Partial Content',
207 : 'Multi-Status', // RFC 4918
300 : 'Multiple Choices',
301 : 'Moved Permanently',
302 : 'Moved Temporarily',
303 : 'See Other',
304 : 'Not Modified',
305 : 'Use Proxy',
307 : 'Temporary Redirect',
400 : 'Bad Request',
401 : 'Unauthorized',
402 : 'Payment Required',
403 : 'Forbidden',
404 : 'Not Found',
405 : 'Method Not Allowed',
406 : 'Not Acceptable',
407 : 'Proxy Authentication Required',
408 : 'Request Time-out',
409 : 'Conflict',
410 : 'Gone',
411 : 'Length Required',
412 : 'Precondition Failed',
413 : 'Request Entity Too Large',
414 : 'Request-URI Too Large',
415 : 'Unsupported Media Type',
416 : 'Requested Range Not Satisfiable',
417 : 'Expectation Failed',
418 : 'I\'m a teapot', // RFC 2324
422 : 'Unprocessable Entity', // RFC 4918
423 : 'Locked', // RFC 4918
424 : 'Failed Dependency', // RFC 4918
425 : 'Unordered Collection', // RFC 4918
426 : 'Upgrade Required', // RFC 2817
500 : 'Internal Server Error',
501 : 'Not Implemented',
502 : 'Bad Gateway',
503 : 'Service Unavailable',
504 : 'Gateway Time-out',
505 : 'HTTP Version not supported',
506 : 'Variant Also Negotiates', // RFC 2295
507 : 'Insufficient Storage', // RFC 4918
509 : 'Bandwidth Limit Exceeded',
510 : 'Not Extended' // RFC 2774
};
}); // module: utils/constants.js
require.register("utils/eql.js", function(module, exports, require){

@@ -1536,6 +2044,5 @@ // This is directly from Node.js assert

}); // module: utils/inspect.js
chai = require('chai');
expect = chai.expect;
assert = chai.assert;
return require('chai');
});
0.1.2 / 2011-12-18
==================
* [docs] for upcoming 0.1.2
* browser version built with pre/suffix … all tests passing
* make / compile now use prefix/suffix correctly
* code clean
* prefix/suffix to wrap browser output to prevent conflicts with other `require` methods.
* Merge branch 'feature/should4xcompatibility'
* compile for browser tests.. all pass
* added header/status/html/json
* throw tests
* should.throw & should.not.throw shortcuts
* improved `throw` type detection and messaging
* contain is now `include` … keys modifier is now `contain`
* removed object() test
* removed #respondTo
* Merge branch 'bug/2'
* replaced __defineGetter__ with defineProperty for all uses
* [docs] change mp tracking code
* docs site updated with assert (TDD) interface
* updated doc comments for assert interface
0.1.1 / 2011-12-16

@@ -3,0 +26,0 @@ ==================

355

lib/assertion.js

@@ -42,3 +42,4 @@ /*!

, eql = require('./utils/eql')
, inspect = require('./utils/inspect');
, inspect = require('./utils/inspect')
, statusCodes = require('./utils/constants').STATUS_CODES;

@@ -67,4 +68,3 @@ /*!

*
* Executes an expression and check expectations.
* Throws AssertionError for reporting.
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
*

@@ -91,3 +91,3 @@ * @name assert

/*!
* # inpsect
* # inspect
*

@@ -100,4 +100,6 @@ * Returns the current object stringified.

Assertion.prototype.__defineGetter__('inspect', function () {
return inspect(this.obj);
Object.defineProperty(Assertion.prototype, 'inspect',
{ get: function () {
return inspect(this.obj);
}
});

@@ -114,4 +116,6 @@

Assertion.prototype.__defineGetter__('to', function () {
return this;
Object.defineProperty(Assertion.prototype, 'to',
{ get: function () {
return this;
}
});

@@ -128,4 +132,6 @@

Assertion.prototype.__defineGetter__('be', function () {
return this;
Object.defineProperty(Assertion.prototype, 'be',
{ get: function () {
return this;
}
});

@@ -142,6 +148,7 @@

Assertion.prototype.__defineGetter__('an', function () {
return this;
Object.defineProperty(Assertion.prototype, 'an',
{ get: function () {
return this;
}
});
/**

@@ -156,4 +163,6 @@ * # is

Assertion.prototype.__defineGetter__('is', function () {
return this;
Object.defineProperty(Assertion.prototype, 'is',
{ get: function () {
return this;
}
});

@@ -170,4 +179,6 @@

Assertion.prototype.__defineGetter__('and', function () {
return this;
Object.defineProperty(Assertion.prototype, 'and',
{ get: function () {
return this;
}
});

@@ -184,4 +195,6 @@

Assertion.prototype.__defineGetter__('have', function () {
return this;
Object.defineProperty(Assertion.prototype, 'have',
{ get: function () {
return this;
}
});

@@ -198,4 +211,6 @@

Assertion.prototype.__defineGetter__('with', function () {
return this;
Object.defineProperty(Assertion.prototype, 'with',
{ get: function () {
return this;
}
});

@@ -212,5 +227,7 @@

Assertion.prototype.__defineGetter__('not', function () {
this.negate = true;
return this;
Object.defineProperty(Assertion.prototype, 'not',
{ get: function () {
this.negate = true;
return this;
}
});

@@ -232,9 +249,11 @@

Assertion.prototype.__defineGetter__('ok', function () {
this.assert(
this.obj
, 'expected ' + this.inspect + ' to be truthy'
, 'expected ' + this.inspect + ' to be falsey');
Object.defineProperty(Assertion.prototype, 'ok',
{ get: function () {
this.assert(
this.obj
, 'expected ' + this.inspect + ' to be truthy'
, 'expected ' + this.inspect + ' to be falsey');
return this;
return this;
}
});

@@ -251,9 +270,11 @@

Assertion.prototype.__defineGetter__('true', function () {
this.assert(
true === this.obj
, 'expected ' + this.inspect + ' to be true'
, 'expected ' + this.inspect + ' to be false');
Object.defineProperty(Assertion.prototype, 'true',
{ get: function () {
this.assert(
true === this.obj
, 'expected ' + this.inspect + ' to be true'
, 'expected ' + this.inspect + ' to be false');
return this;
return this;
}
});

@@ -270,9 +291,11 @@

Assertion.prototype.__defineGetter__('false', function () {
this.assert(
false === this.obj
, 'expected ' + this.inspect + ' to be false'
, 'expected ' + this.inspect + ' to be true');
Object.defineProperty(Assertion.prototype, 'false',
{ get: function () {
this.assert(
false === this.obj
, 'expected ' + this.inspect + ' to be false'
, 'expected ' + this.inspect + ' to be true');
return this;
return this;
}
});

@@ -294,9 +317,11 @@

Assertion.prototype.__defineGetter__('exist', function () {
this.assert(
null != this.obj
, 'expected ' + this.inspect + ' to exist'
, 'expected ' + this.inspect + ' to not exist');
Object.defineProperty(Assertion.prototype, 'exist',
{ get: function () {
this.assert(
null != this.obj
, 'expected ' + this.inspect + ' to exist'
, 'expected ' + this.inspect + ' to not exist');
return this;
return this;
}
});

@@ -315,11 +340,13 @@

Assertion.prototype.__defineGetter__('empty', function () {
new Assertion(this.obj).to.have.property('length');
Object.defineProperty(Assertion.prototype, 'empty',
{ get: function () {
new Assertion(this.obj).to.have.property('length');
this.assert(
0 === this.obj.length
, 'expected ' + this.inspect + ' to be empty'
, 'expected ' + this.inspect + ' not to be empty');
this.assert(
0 === this.obj.length
, 'expected ' + this.inspect + ' to be empty'
, 'expected ' + this.inspect + ' not to be empty');
return this;
return this;
}
});

@@ -340,9 +367,11 @@

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

@@ -483,5 +512,7 @@

*
* expect(42).to.be.instanceof(Number);
* expect([4,2]).to.be.instanceof(Array);
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
*
* expect(Chai).to.be.an.instanceOf(Tea);
*
* @name instanceOf

@@ -503,28 +534,5 @@ * @param {Constructor}

/**
* # respondTo(method)
*
* Assert that `method` is a function.
*
* var res = { send: function () {} };
* expect(res).to.respondTo('send');
*
* @name respondTo
* @param {String} method name
* @api public
*/
Assertion.prototype.respondTo = function (method) {
this.assert(
'function' == typeof this.obj[method]
, 'expected ' + this.inspect + ' to respond to ' + method + '()'
, 'expected ' + this.inspect + ' to not respond to ' + method + '()');
return this;
}
/**
* # .property(name, [value])
*
* Assert that property of `name` exists,
* optionally with `value`.
* Assert that property of `name` exists, optionally with `value`.
*

@@ -636,9 +644,9 @@ * var obj = { foo: 'bar' }

/**
* # .contain(obj)
* # .include(obj)
*
* Assert the inclusion of an object in an Array
* Assert the inclusion of an object in an Array or substring in string.
*
* expect([1,2,3]).to.contain(2);
*
* @name contain
* @name include
* @param {Object|String|Number} obj

@@ -648,9 +656,7 @@ * @api public

Assertion.prototype.contain = function (obj) {
new Assertion(this.obj).to.be.an.instanceof(Array);
Assertion.prototype.include = function (obj) {
this.assert(
~this.obj.indexOf(obj)
, 'expected ' + this.inspect + ' to contain ' + inspect(obj)
, 'expected ' + this.inspect + ' to not contain ' + inspect(obj));
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));

@@ -677,4 +683,4 @@ return this;

~this.obj.indexOf(str)
, 'expected ' + this.inspect + ' to include ' + inspect(str)
, 'expected ' + this.inspect + ' to not include ' + inspect(str));
, 'expected ' + this.inspect + ' to contain ' + inspect(str)
, 'expected ' + this.inspect + ' to not contain ' + inspect(str));

@@ -684,47 +690,18 @@ return this;

/**
* # .object(object)
*
* Assert inclusion of object in object.
*
* var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
* expect(obj).to.include.object({foo: 'bar'});
*
* @name object
* @param {Object} object
* @api public
*/
Assertion.prototype.object = function(obj){
new Assertion(this.obj).is.a('object');
var included = true;
for (var key in obj) {
if (obj.hasOwnProperty(key) && !eql(obj[key], this.obj[key])) {
included = false;
break;
}
}
this.assert(
included
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));
return this;
}
/**
* # include
* # contain
*
* Language chain that lags #keys to test for inclusion testing.
* Toggles the `contain` flag for the `keys` assertion.
*
* @name include
* @name contain
* @api public
*/
Assertion.prototype.__defineGetter__('include', function () {
this.includes = true;
return this;
Object.defineProperty(Assertion.prototype, 'contain',
{ get: function () {
this.contains = true;
return this;
}
});

@@ -735,7 +712,6 @@

*
* Assert exact keys or the inclusing of keys using
* the include modifier.
* 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.include.keys('foo', 'bar');
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
*

@@ -767,3 +743,3 @@ * @name keys

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

@@ -787,3 +763,3 @@ }

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

@@ -802,4 +778,3 @@ // Assertion

*
* Assert that a function will throw a specific
* type of error.
* Assert that a function will throw a specific type of error.
*

@@ -819,5 +794,3 @@ * var fn = function () { throw new ReferenceError(''); }

constructor = constructor || Error;
var name = constructor.name
, thrown = false;
var thrown = false;

@@ -827,10 +800,16 @@ try {

} catch (err) {
thrown = true;
this.assert(
err instanceof constructor
, 'expected ' + this.inspect + ' to throw ' + name
, 'expected ' + this.inspect + ' to not throw ' + name);
return this;
if (constructor) {
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 );
return this;
} else {
thrown = true;
}
}
var name = (constructor ? constructor.name : 'an error');
this.assert(

@@ -840,4 +819,80 @@ thrown === true

, 'expected ' + this.inspect + ' to not throw ' + name);
return this;
};
/**
* # .header(code)
*
* Assert `header` field has expected `value`.
*
* @name header
* @param {String} field
* @param {String} value
* @api public
*/
Assertion.prototype.header = function (field, val) {
new Assertion(this.obj)
.to.have.property('headers').and
.to.have.property(field.toLowerCase(), val);
return this;
}
/**
* # .status(code)
*
* Assert `statusCode` of `code'.
*
* @name status
* @param {Number} code
* @api public
*/
Assertion.prototype.status = function (code) {
new Assertion(this.obj).to.have.property('statusCode');
var status = this.obj.statusCode;
this.assert(
code == status
, 'expected response code of ' + code + ' ' + inspect(statusCodes[code])
+ ', but got ' + status + ' ' + inspect(statusCodes[status])
, 'expected to not respond with ' + code + ' ' + inspect(statusCodes[code]));
}
/**
* # json
*
* Assert that this response has content-type: application/json.
*
* @name json
* @api public
*/
Object.defineProperty(Assertion.prototype, 'json',
{ get: function () {
new Assertion(this.obj).to.have.header('content-type', 'application/json; charset=utf-8');
return this;
}
});
/**
* # html
*
* Assert that this response has content-type: text/html.
*
* @name html
* @api public
*/
Object.defineProperty(Assertion.prototype, 'html',
{ get: function () {
new Assertion(this.obj).to.have.header('content-type', 'text/html; charset=utf-8');
return this;
}
});
/*!

@@ -844,0 +899,0 @@ * Aliases.

@@ -9,3 +9,3 @@ /*!

exports.version = '0.1.1';
exports.version = '0.1.2';

@@ -12,0 +12,0 @@ exports.expect = require('./interface/expect');

@@ -7,6 +7,43 @@ /*!

/**
* ### 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');
*/
/*!
* Module dependencies.
*/
var Assertion = require('../assertion');
/*!
* Module export.
*/
var assert = module.exports = {};
/**
* # .ok(object, [message])
*
* Assert object is truthy.
*
* assert.ok('everthing', 'everything is ok');
* assert.ok(false, 'this will fail');
*
* @name ok
* @param {*} object to test
* @param {String} message
* @api public
*/
assert.ok = function (val, msg) {

@@ -16,2 +53,16 @@ new Assertion(val, msg).is.ok;

/**
* # .equal(actual, expected, [message])
*
* Assert strict equality.
*
* assert.equal(3, 3, 'these numbers are equal');
*
* @name equal
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.equal = function (act, exp, msg) {

@@ -21,2 +72,16 @@ new Assertion(act, msg).to.equal(exp);

/**
* # .notEqual(actual, expected, [message])
*
* Assert not strict equality.
*
* assert.notEqual(3, 4, 'these numbers are not equal');
*
* @name notEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.notEqual = function (act, exp, msg) {

@@ -26,2 +91,16 @@ new Assertion(act, msg).to.not.equal(exp);

/**
* # .deepEqual(actual, expected, [message])
*
* Assert not deep equality.
*
* assert.deepEqual({ tea: 'green' }, { tea: 'green' });
*
* @name deepEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.deepEqual = function (act, exp, msg) {

@@ -31,2 +110,16 @@ new Assertion(act, msg).to.eql(exp);

/**
* # .notDeepEqual(actual, expected, [message])
*
* Assert not deep equality.
*
* assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
*
* @name notDeepEqual
* @param {*} actual
* @param {*} expected
* @param {String} message
* @api public
*/
assert.notDeepEqual = function (act, exp, msg) {

@@ -36,2 +129,16 @@ new Assertion(act, msg).to.not.eql(exp);

/**
* # .isTrue(value, [message])
*
* Assert `value` is true.
*
* var tea_served = true;
* assert.isTrue(tea_served, 'the tea has been served');
*
* @name isTrue
* @param {Boolean} value
* @param {String} message
* @api public
*/
assert.isTrue = function (val, msg) {

@@ -41,2 +148,16 @@ new Assertion(val, msg).is.true;

/**
* # .isFalse(value, [message])
*
* Assert `value` is false.
*
* var tea_served = false;
* assert.isFalse(tea_served, 'no tea yet? hmm...');
*
* @name isFalse
* @param {Boolean} value
* @param {String} message
* @api public
*/
assert.isFalse = function (val, msg) {

@@ -46,2 +167,15 @@ new Assertion(val, msg).is.false;

/**
* # .isNull(value, [message])
*
* Assert `value` is null.
*
* assert.isNull(err, 'no errors');
*
* @name isNull
* @param {*} value
* @param {String} message
* @api public
*/
assert.isNull = function (val, msg) {

@@ -51,2 +185,16 @@ new Assertion(val, msg).to.not.exist;

/**
* # .isNotNull(value, [message])
*
* Assert `value` is not null.
*
* var tea = 'tasty chai';
* assert.isNotNull(tea, 'great, time for tea!');
*
* @name isNotNull
* @param {*} value
* @param {String} message
* @api public
*/
assert.isNotNull = function (val, msg) {

@@ -56,2 +204,15 @@ new Assertion(val, msg).to.exist;

/**
* # .isUndefined(value, [message])
*
* Assert `value` is undefined.
*
* assert.isUndefined(tea, 'no tea defined');
*
* @name isUndefined
* @param {*} value
* @param {String} message
* @api public
*/
assert.isUndefined = function (val, msg) {

@@ -61,5 +222,15 @@ new Assertion(val, msg).to.equal(undefined);

assert.isNan = function (val, msg) {
new Assertion(val, msg).to.not.equal(val);
};
/**
* # .isFunction(value, [message])
*
* Assert `value` is a function.
*
* var serve_tea = function () { return 'cup of tea'; };
* assert.isFunction(serve_tea, 'great, we can have tea now');
*
* @name isFunction
* @param {Function} value
* @param {String} message
* @api public
*/

@@ -70,2 +241,16 @@ assert.isFunction = function (val, msg) {

/**
* # .isObject(value, [message])
*
* Assert `value` is an object.
*
* var selection = { name: 'Chai', serve: 'with spices' };
* assert.isObject(selection, 'tea selection is an object');
*
* @name isObject
* @param {Object} value
* @param {String} message
* @api public
*/
assert.isObject = function (val, msg) {

@@ -75,5 +260,15 @@ new Assertion(val, msg).to.be.an('object');

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

@@ -84,2 +279,34 @@ assert.isArray = function (val, msg) {

/**
* # .isString(value, [message])
*
* Assert `value` is a string.
*
* var teaorder = 'chai';
* assert.isString(tea_order, 'order placed');
*
* @name isString
* @param {String} value
* @param {String} message
* @api public
*/
assert.isString = function (val, msg) {
new Assertion(val, msg).to.be.a('string');
};
/**
* # .isNumber(value, [message])
*
* Assert `value` is a number
*
* var cups = 2;
* assert.isNumber(cups, 'how many cups');
*
* @name isNumber
* @param {Number} value
* @param {String} message
* @api public
*/
assert.isNumber = function (val, msg) {

@@ -89,2 +316,19 @@ new Assertion(val, msg).to.be.instanceof(Number);

/**
* # .isBoolean(value, [message])
*
* Assert `value` is a boolean
*
* var teaready = true
* , teaserved = false;
*
* assert.isBoolean(tea_ready, 'is the tea ready');
* assert.isBoolean(tea_served, 'has tea been served');
*
* @name isBoolean
* @param {*} value
* @param {String} message
* @api public
*/
assert.isBoolean = function (val, msg) {

@@ -94,2 +338,16 @@ new Assertion(val, msg).to.be.a('boolean');

/**
* # .typeOf(value, name, [message])
*
* Assert typeof `value` is `name`.
*
* assert.typeOf('tea', 'string', 'we have a string');
*
* @name typeOf
* @param {*} value
* @param {String} typeof name
* @param {String} message
* @api public
*/
assert.typeOf = function (val, type, msg) {

@@ -99,2 +357,19 @@ new Assertion(val, msg).to.be.a(type);

/**
* # .instanceOf(object, constructor, [message])
*
* Assert `value` is instanceof `constructor`.
*
* var Tea = function (name) { this.name = name; }
* , Chai = new Tea('chai');
*
* assert.instanceOf(Chai, Tea, 'chai is an instance of tea');
*
* @name instanceOf
* @param {Object} object
* @param {Constructor} constructor
* @param {String} message
* @api public
*/
assert.instanceOf = function (val, type, msg) {

@@ -104,6 +379,46 @@ new Assertion(val, msg).to.be.instanceof(type);

/**
* # .include(value, includes, [message])
*
* Assert the inclusion of an object in another.
*
* var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
* assert.include(obj, {foo: 'bar'}, 'object contains subobject');
*
* assert.include('foobar', 'bar', 'foobar contains string `var`);
* assert.include([ 1, 2, 3], 3, 'array contains value);
*
* @name include
* @param {Array|String|Object} value
* @param {*} includes
* @param {String} message
* @api public
*/
assert.include = function (exp, inc, msg) {
new Assertion(exp, msg).to.include(inc);
var obj = new Assertion(exp, msg);
if (Array.isArray(exp)) {
obj.to.contain(inc);
} else if ('string' === typeof exp) {
obj.to.include.string(inc);
} else {
obj.to.include.object(inc);
}
};
/**
* # .match(value, constructor, [message])
*
* Assert that `value` matches regular expression.
*
* assert.match('foobar', /^foo/, 'Regexp matches');
*
* @name match
* @param {*} value
* @param {RegExp} RegularExpression
* @param {String} message
* @api public
*/
assert.match = function (exp, re, msg) {

@@ -113,2 +428,17 @@ new Assertion(exp, msg).to.match(re);

/**
* # .length(value, constructor, [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');
*
* @name length
* @param {*} value
* @param {Number} length
* @param {String} message
* @api public
*/
assert.length = function (exp, len, msg) {

@@ -118,4 +448,37 @@ new Assertion(exp, msg).to.have.length(len);

assert.throws = function (fn, type, msg) {
/**
* # .throw(function, constructor, [message])
*
* Assert that a function will throw a specific
* type of error.
*
* var fn = function () { throw new ReferenceError(''); }
* assert.throw(fn, ReferenceError, 'function throw reference error');
*
* @name throw
* @alias throws
* @param {Function} function to test
* @param {ErrorConstructor} constructor
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @api public
*/
assert.throw = function (fn, type, msg) {
new Assertions(fn, msg).to.throw(type);
};
};
/*!
* Aliases.
*/
(function alias(name, as){
assert[as] = assert[name];
return alias;
})
('length', 'lengthOf');
//('keys', 'key')
//('ownProperty', 'haveOwnProperty')
//('above', 'greaterThan')
//('below', 'lessThan')
//('throw', 'throws');

@@ -36,3 +36,18 @@ /*!

should.throw = function (fn, err) {
new Assertion(fn).to.throw(err);
};
// negation
should.not = {}
should.not.equal = function (val1, val2) {
new Assertion(val).to.not.equal(val2);
};
should.not.throw = function (fn, err) {
new Assertion(fn).to.not.throw(err);
};
return should;
};

@@ -6,3 +6,3 @@ {

"keywords": [ "test", "assertion", "assert", "testing" ],
"version": "0.1.1",
"version": "0.1.2",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

@@ -1,2 +0,3 @@

var fs = require('fs');
var fs = require('fs')
, join = require('path').join;

@@ -35,2 +36,7 @@ var args = process.argv.slice(2)

var prefix = fs.readFileSync(join(__dirname, 'prefix.js'), 'utf8')
, suffix = fs.readFileSync(join(__dirname, 'suffix.js'), 'utf8');
buf = prefix + '\n' + buf + '\n' + suffix;
fs.writeFile('chai.js', buf, function(err){

@@ -37,0 +43,0 @@ if (err) throw err;

@@ -1,5 +0,3 @@

chai = require('chai');
expect = chai.expect;
assert = chai.assert;
return require('chai');
});

@@ -1,8 +0,9 @@

/**
/*!
* Module dependencies.
*
* Chai is automatically included in the browser.
*/
// if we are in a browser session, chai is already defined
if (!chai) {
var chai = require('../');
var chai = require('..');
}

@@ -252,58 +253,36 @@

'test string()': function(){
expect('foobar').to.include.string('bar');
expect('foobar').to.include.string('foo');
expect('foobar').to.not.include.string('baz');
expect('foobar').to.have.string('bar');
expect('foobar').to.have.string('foo');
expect('foobar').to.not.have.string('baz');
err(function(){
expect(3).to.include.string('baz');
expect(3).to.have.string('baz');
}, "expected 3 to be a string");
err(function(){
expect('foobar').to.include.string('baz');
}, "expected 'foobar' to include 'baz'");
expect('foobar').to.have.string('baz');
}, "expected 'foobar' to contain 'baz'");
err(function(){
expect('foobar').to.not.include.string('bar');
}, "expected 'foobar' to not include 'bar'");
expect('foobar').to.not.have.string('bar');
}, "expected 'foobar' to not contain 'bar'");
},
'test object()': function(){
var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
expect(obj).to.include.object({foo: 'bar'});
expect(obj).to.include.object({baz: {baaz: 42}});
expect(obj).to.include.object({foo: 'bar', qux: 13});
expect(obj).to.not.include.object({foo: 'baz'});
expect(obj).to.not.include.object({foo: 'bar', baz: {baaz: -42}});
'test include()': function(){
expect(['foo', 'bar']).to.include('foo');
expect(['foo', 'bar']).to.include('foo');
expect(['foo', 'bar']).to.include('bar');
expect([1,2]).to.include(1);
expect(['foo', 'bar']).to.not.include('baz');
expect(['foo', 'bar']).to.not.include(1);
err(function(){
expect(3).to.include.object({foo: 'bar'});
}, "expected 3 to be a object");
expect(['foo']).to.include('bar');
}, "expected [ 'foo' ] to include 'bar'");
err(function(){
var obj = {foo: 'bar'};
expect(obj).to.include.object({foo: 'baz'});
}, "expected { foo: 'bar' } to include { foo: 'baz' }");
err(function(){
var obj = {foo: 'bar'};
expect(obj).to.not.include.object({foo: 'bar'});
}, "expected { foo: 'bar' } to not include { foo: 'bar' }");
expect(['bar', 'foo']).to.not.include('foo');
}, "expected [ 'bar', 'foo' ] to not include 'foo'");
},
'test contain()': function(){
expect(['foo', 'bar']).to.contain('foo');
expect(['foo', 'bar']).to.contain('foo');
expect(['foo', 'bar']).to.contain('bar');
expect([1,2]).to.contain(1);
expect(['foo', 'bar']).to.not.contain('baz');
expect(['foo', 'bar']).to.not.contain(1);
err(function(){
expect(['foo']).to.contain('bar');
}, "expected [ 'foo' ] to contain 'bar'");
err(function(){
expect(['bar', 'foo']).to.not.contain('foo');
}, "expected [ 'bar', 'foo' ] to not contain 'foo'");
},
'test keys(array)': function(){

@@ -313,17 +292,17 @@ expect({ foo: 1 }).to.have.keys(['foo']);

expect({ foo: 1, bar: 2 }).to.have.keys('foo', 'bar');
expect({ foo: 1, bar: 2, baz: 3 }).to.include.keys('foo', 'bar');
expect({ foo: 1, bar: 2, baz: 3 }).to.include.keys('bar', 'foo');
expect({ foo: 1, bar: 2, baz: 3 }).to.include.keys('baz');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('bar', 'foo');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('baz');
expect({ foo: 1, bar: 2 }).to.include.keys('foo');
expect({ foo: 1, bar: 2 }).to.include.keys('bar', 'foo');
expect({ foo: 1, bar: 2 }).to.include.keys(['foo']);
expect({ foo: 1, bar: 2 }).to.include.keys(['bar']);
expect({ foo: 1, bar: 2 }).to.include.keys(['bar', 'foo']);
expect({ foo: 1, bar: 2 }).to.contain.keys('foo');
expect({ foo: 1, bar: 2 }).to.contain.keys('bar', 'foo');
expect({ foo: 1, bar: 2 }).to.contain.keys(['foo']);
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar']);
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar', 'foo']);
expect({ foo: 1, bar: 2 }).to.not.have.keys('baz');
expect({ foo: 1, bar: 2 }).to.not.have.keys('foo', 'baz');
expect({ foo: 1, bar: 2 }).to.not.include.keys('baz');
expect({ foo: 1, bar: 2 }).to.not.include.keys('foo', 'baz');
expect({ foo: 1, bar: 2 }).to.not.include.keys('baz', 'foo');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('foo', 'baz');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz', 'foo');

@@ -343,3 +322,3 @@ err(function(){

err(function(){
expect({ foo: 1 }).to.include.keys([]);
expect({ foo: 1 }).to.contain.keys([]);
}, "keys required");

@@ -372,26 +351,65 @@

err(function(){
expect({ foo: 1 }).to.not.include.keys(['foo']);
}, "expected { foo: 1 } to not include key 'foo'");
expect({ foo: 1 }).to.not.contain.keys(['foo']);
}, "expected { foo: 1 } to not contain key 'foo'");
err(function(){
expect({ foo: 1 }).to.include.keys('foo', 'bar');
}, "expected { foo: 1 } to include keys 'foo', and 'bar'");
expect({ foo: 1 }).to.contain.keys('foo', 'bar');
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
},
'test respondTo(method)': function(){
expect('test').to.respondTo('toString');
expect('test').to.not.respondTo('toBuffer');
'test chaining': function(){
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] };
expect(tea).to.have.property('extras').with.lengthOf(3);
err(function(){
expect(tea).to.have.property('extras').with.lengthOf(4);
}, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3");
expect(tea).to.be.a('object').and.have.property('name', 'chai');
},
'test chaining': function(){
var user = { name: 'tj', pets: ['tobi', 'loki', 'jane', 'bandit'] };
expect(user).to.have.property('pets').with.lengthOf(4);
'test throw': function () {
var goodFn = function () { 1==1; }
, badFn = function () { throw new Error('testing'); }
, refErrFn = function () { throw new ReferenceError(); };
expect(goodFn).to.not.throw();
expect(goodFn).to.not.throw(Error);
expect(badFn).to.throw();
expect(badFn).to.throw(Error);
expect(badFn).to.not.throw(ReferenceError);
expect(refErrFn).to.throw();
expect(refErrFn).to.throw(ReferenceError);
expect(refErrFn).to.not.throw(Error);
expect(refErrFn).to.not.throw(TypeError);
err(function(){
expect(user).to.have.property('pets').with.lengthOf(5);
}, "expected [ 'tobi', 'loki', 'jane', 'bandit' ] to have a length of 5 but got 4");
expect(goodFn).to.throw();
}, "expected [Function] to throw an error");
expect(user).to.be.a('object').and.have.property('name', 'tj');
err(function(){
expect(goodFn).to.throw(ReferenceError);
}, "expected [Function] to throw ReferenceError");
err(function(){
expect(badFn).to.not.throw();
}, "expected [Function] to not throw an error");
err(function(){
expect(badFn).to.throw(ReferenceError);
}, "expected [Function] to throw ReferenceError but a Error was thrown");
err(function(){
expect(badFn).to.not.throw(Error);
}, "expected [Function] to not throw Error");
err(function(){
expect(refErrFn).to.not.throw(ReferenceError);
}, "expected [Function] to not throw ReferenceError");
err(function(){
expect(refErrFn).to.throw(Error);
}, "expected [Function] to throw Error but a ReferenceError was thrown");
}
}
};

@@ -241,58 +241,36 @@ /**

'test string()': function(){
'foobar'.should.include.string('bar');
'foobar'.should.include.string('foo');
'foobar'.should.not.include.string('baz');
'foobar'.should.contain.string('bar');
'foobar'.should.contain.string('foo');
'foobar'.should.not.contain.string('baz');
err(function(){
(3).should.include.string('baz');
(3).should.contain.string('baz');
}, "expected 3 to be a string");
err(function(){
'foobar'.should.include.string('baz');
}, "expected 'foobar' to include 'baz'");
'foobar'.should.contain.string('baz');
}, "expected 'foobar' to contain 'baz'");
err(function(){
'foobar'.should.not.include.string('bar');
}, "expected 'foobar' to not include 'bar'");
'foobar'.should.not.contain.string('bar');
}, "expected 'foobar' to not contain 'bar'");
},
'test object()': function(){
var obj = {foo: 'bar', baz: {baaz: 42}, qux: 13};
obj.should.include.object({foo: 'bar'});
obj.should.include.object({baz: {baaz: 42}});
obj.should.include.object({foo: 'bar', qux: 13});
obj.should.not.include.object({foo: 'baz'});
obj.should.not.include.object({foo: 'bar', baz: {baaz: -42}});
'test include()': function(){
['foo', 'bar'].should.include('foo');
['foo', 'bar'].should.include('foo');
['foo', 'bar'].should.include('bar');
[1,2].should.include(1);
['foo', 'bar'].should.not.include('baz');
['foo', 'bar'].should.not.include(1);
err(function(){
(3).should.include.object({foo: 'bar'});
}, "expected 3 to be a object");
['foo'].should.include('bar');
}, "expected [ 'foo' ] to include 'bar'");
err(function(){
var obj = {foo: 'bar'};
obj.should.include.object({foo: 'baz'});
}, "expected { foo: 'bar' } to include { foo: 'baz' }");
err(function(){
var obj = {foo: 'bar'};
obj.should.not.include.object({foo: 'bar'});
}, "expected { foo: 'bar' } to not include { foo: 'bar' }");
['bar', 'foo'].should.not.include('foo');
}, "expected [ 'bar', 'foo' ] to not include 'foo'");
},
'test contain()': function(){
['foo', 'bar'].should.contain('foo');
['foo', 'bar'].should.contain('foo');
['foo', 'bar'].should.contain('bar');
[1,2].should.contain(1);
['foo', 'bar'].should.not.contain('baz');
['foo', 'bar'].should.not.contain(1);
err(function(){
['foo'].should.contain('bar');
}, "expected [ 'foo' ] to contain 'bar'");
err(function(){
['bar', 'foo'].should.not.contain('foo');
}, "expected [ 'bar', 'foo' ] to not contain 'foo'");
},
'test keys(array)': function(){

@@ -302,17 +280,17 @@ ({ foo: 1 }).should.have.keys(['foo']);

({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar');
({ foo: 1, bar: 2, baz: 3 }).should.include.keys('foo', 'bar');
({ foo: 1, bar: 2, baz: 3 }).should.include.keys('bar', 'foo');
({ foo: 1, bar: 2, baz: 3 }).should.include.keys('baz');
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('foo', 'bar');
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('bar', 'foo');
({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('baz');
({ foo: 1, bar: 2 }).should.include.keys('foo');
({ foo: 1, bar: 2 }).should.include.keys('bar', 'foo');
({ foo: 1, bar: 2 }).should.include.keys(['foo']);
({ foo: 1, bar: 2 }).should.include.keys(['bar']);
({ foo: 1, bar: 2 }).should.include.keys(['bar', 'foo']);
({ foo: 1, bar: 2 }).should.contain.keys('foo');
({ foo: 1, bar: 2 }).should.contain.keys('bar', 'foo');
({ foo: 1, bar: 2 }).should.contain.keys(['foo']);
({ foo: 1, bar: 2 }).should.contain.keys(['bar']);
({ foo: 1, bar: 2 }).should.contain.keys(['bar', 'foo']);
({ foo: 1, bar: 2 }).should.not.have.keys('baz');
({ foo: 1, bar: 2 }).should.not.have.keys('foo', 'baz');
({ foo: 1, bar: 2 }).should.not.include.keys('baz');
({ foo: 1, bar: 2 }).should.not.include.keys('foo', 'baz');
({ foo: 1, bar: 2 }).should.not.include.keys('baz', 'foo');
({ foo: 1, bar: 2 }).should.not.contain.keys('baz');
({ foo: 1, bar: 2 }).should.not.contain.keys('foo', 'baz');
({ foo: 1, bar: 2 }).should.not.contain.keys('baz', 'foo');

@@ -332,3 +310,3 @@ err(function(){

err(function(){
({ foo: 1 }).should.include.keys([]);
({ foo: 1 }).should.contain.keys([]);
}, "keys required");

@@ -361,26 +339,59 @@

err(function(){
({ foo: 1 }).should.not.include.keys(['foo']);
}, "expected { foo: 1 } to not include key 'foo'");
({ foo: 1 }).should.not.contain.keys(['foo']);
}, "expected { foo: 1 } to not contain key 'foo'");
err(function(){
({ foo: 1 }).should.include.keys('foo', 'bar');
}, "expected { foo: 1 } to include keys 'foo', and 'bar'");
({ foo: 1 }).should.contain.keys('foo', 'bar');
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
},
'test respondTo(method)': function(){
'test'.should.respondTo('toString');
'test'.should.not.respondTo('toBuffer');
},
'test throw': function () {
var goodFn = function () { 1==1; }
, badFn = function () { throw new Error('testing'); }
, refErrFn = function () { throw new ReferenceError(); };
'test chaining': function(){
var user = { name: 'tj', pets: ['tobi', 'loki', 'jane', 'bandit'] };
user.should.have.property('pets').with.lengthOf(4);
(goodFn).should.not.throw();
(goodFn).should.not.throw(Error);
(badFn).should.throw();
(badFn).should.throw(Error);
(badFn).should.not.throw(ReferenceError);
(refErrFn).should.throw();
(refErrFn).should.throw(ReferenceError);
(refErrFn).should.not.throw(Error);
(refErrFn).should.not.throw(TypeError);
should.throw(badFn);
should.throw(refErrFn, ReferenceError);
should.not.throw(goodFn);
should.not.throw(badFn, ReferenceError);
err(function(){
user.should.have.property('pets').with.lengthOf(5);
}, "expected [ 'tobi', 'loki', 'jane', 'bandit' ] to have a length of 5 but got 4");
(goodFn).should.throw();
}, "expected [Function] to throw an error");
user.should.be.a('object').and.have.property('name', 'tj');
err(function(){
(goodFn).should.throw(ReferenceError);
}, "expected [Function] to throw ReferenceError");
err(function(){
(badFn).should.not.throw();
}, "expected [Function] to not throw an error");
err(function(){
(badFn).should.throw(ReferenceError);
}, "expected [Function] to throw ReferenceError but a Error was thrown");
err(function(){
(badFn).should.not.throw(Error);
}, "expected [Function] to not throw Error");
err(function(){
(refErrFn).should.not.throw(ReferenceError);
}, "expected [Function] to not throw ReferenceError");
err(function(){
(refErrFn).should.throw(Error);
}, "expected [Function] to throw Error but a ReferenceError was thrown");
}
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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