Namespace: Assert

Assert

Assert

Assert

Assert

Assert

.isObject(value, [message])

Asserts that value is an object of type 'Object' (as revealed by Object.prototype.toString). The assertion does not match subclassed objects.

var selection = { name: 'Chai', serve: 'with spices' };
assert.isObject(selection, 'tea selection is an object');
Source:

Assert

.isNotObject(value, [message])

Asserts that value is not an object of type 'Object' (as revealed by Object.prototype.toString).

var selection = 'chai'
assert.isNotObject(selection, 'tea selection is not an object');
assert.isNotObject(null, 'null is not an object');
Source:

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

.typeOf(value, name, [message])

Asserts that value's type is name, as determined by Object.prototype.toString.

assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
assert.typeOf('tea', 'string', 'we have a string');
assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
assert.typeOf(null, 'null', 'we have a null');
assert.typeOf(undefined, 'undefined', 'we have an undefined');
Source:

Assert

Assert

.instanceOf(object, constructor, [message])

Asserts that value is an instance of constructor.

var Tea = function (name) { this.name = name; }
  , chai = new Tea('chai');

assert.instanceOf(chai, Tea, 'chai is an instance of tea');
Source:

Assert

.notInstanceOf(object, constructor, [message])

Asserts value is not an instance of constructor.

var Tea = function (name) { this.name = name; }
  , chai = new String('chai');

assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
Source:

Assert

.include(haystack, needle, [message])

Asserts that haystack includes needle. Works for strings and arrays.

assert.include('foobar', 'bar', 'foobar contains string "bar"');
assert.include([ 1, 2, 3 ], 3, 'array contains value');
Source:

Assert

.notInclude(haystack, needle, [message])

Asserts that haystack does not include needle. Works for strings and arrays.

assert.notInclude('foobar', 'baz', 'string not include substring');
assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
Source:

Assert

Assert

Assert

Assert

Assert

.deepProperty(object, property, [message])

Asserts that object has a property named by property, which can be a string using dot- and bracket-notation for deep reference.

assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
Source:

Assert

.notDeepProperty(object, property, [message])

Asserts that object does not have a property named by property, which can be a string using dot- and bracket-notation for deep reference.

assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
Source:

Assert

Assert

Assert

.deepPropertyVal(object, property, value, [message])

Asserts that object has a property named by property with value given by value. property can use dot- and bracket-notation for deep reference.

assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
Source:

Assert

.deepPropertyNotVal(object, property, value, [message])

Asserts that object has a property named by property, but with a value different from that given by value. property can use dot- and bracket-notation for deep reference.

assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
Source:

Assert

Assert

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

Asserts that function will throw an error that is an instance of constructor, or alternately that it will throw an error with message matching regexp.

assert.throws(fn, 'function throws a reference error');
assert.throws(fn, /function throws a reference error/);
assert.throws(fn, ReferenceError);
assert.throws(fn, ReferenceError, 'function throws a reference error');
assert.throws(fn, ReferenceError, /function throws a reference error/);
Source:
See:

Assert

Assert

Assert

Assert

Assert

Assert

.sameDeepMembers(set1, set2, [message])

Asserts that set1 and set2 have the same members - using a deep equality checking. Order is not taken into account.

assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
Source:

Assert

Assert

.includeDeepMembers(superset, subset, [message])

Asserts that subset is included in superset - using deep equality checking. Order is not taken into account. Duplicates are ignored.

assert.includeDeepMembers([ {a: 1}, {b: 2}, {c: 3} ], [ {b: 2}, {a: 1}, {b: 2} ], 'include deep members');
Source:

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

.isNotExtensible(object)

Asserts that object is not extensible.

var nonExtensibleObject = Object.preventExtensions({});
var sealedObject = Object.seal({});
var frozenObject = Object.freese({});

assert.isNotExtensible(nonExtensibleObject);
assert.isNotExtensible(sealedObject);
assert.isNotExtensible(frozenObject);
Source:

Assert

.isSealed(object)

Asserts that object is sealed (cannot have new properties added to it and its existing properties cannot be removed).

var sealedObject = Object.seal({});
var frozenObject = Object.seal({});

assert.isSealed(sealedObject);
assert.isSealed(frozenObject);
Source:

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert

.isAtLeast(valueToCheck, valueToBeAtLeast, [message])

Asserts valueToCheck is greater than or equal to (>=) valueToBeAtLeast

assert.isAtLeast(5, 2, '5 is greater or equal to 2');
assert.isAtLeast(3, 3, '3 is greater or equal to 3');
Source:

Assert

Assert

.isAtMost(valueToCheck, valueToBeAtMost, [message])

Asserts valueToCheck is less than or equal to (<=) valueToBeAtMost

assert.isAtMost(3, 6, '3 is less than or equal to 6');
assert.isAtMost(4, 4, '4 is less than or equal to 4');
Source:

Assert

Assert

Assert

Assert

Assert

Assert

Assert

Assert