A simple assertion library for server and client side JavaScript. Assert can be used with most test frameworks.
Browser Support: Android Browser 2.2–4.2, Firefox 3.6, Firefox 4–22, Google Chrome 14–28, Internet Explorer 6–10, Mobile Safari iOS 3–6, Safari 5–6
All assertions throw AssertionError
if they fail.
Throw an assertion error.
assert.fail('foo', 'bar', 'Foo equals bar', '===');
Assert that value
is truthy.
Assert that value
is falsy.
Assert that actual == expected
.
Assert that actual != expected
.
Assert that actual === expected
.
Assert that actual !== expected
.
Assert that actual
is deeply equal to expected
.
Assert that actual
is not deeply equal to expected
.
Assert that fn
throws an error. If expected
is present then the thrown error
will be tested as follows:
- If
expected
is a function, assert thaterror intanceof expected
- If
expected
is a string, assert thaterror.message === expected
- If
expected
is a RegExp, assert thatexpected.test(error) === true
Assert that fn
does not throw an error. If expected
is present then the assertion is that an error can be thrown, but it does not pass the tests outlined in assert.throws
.
Assert that typeof actual === expected
.
Assert that typeof actual !== expected
.
Assert that actual instanceof expected
.
Assert that !(actual instanceof expected)
.
Assert that value
is an array
.
Assert that value
is not an array
.
Assert that value
is a boolean
.
Assert that value
is not a boolean
.
Assert that value === true
.
Assert that value === false
.
Assert that value
is a function
.
Assert that value
is not a function
.
Assert that value === null
.
Assert that value !== null
.
Assert that value
is a number
.
Assert that value
is not a number
.
Assert that value
is an object
.
Assert that value
is not an object
.
Assert that value
is a string
.
Assert that value
is not a string
.
Assert that value === undefined
.
Assert that value !== undefined
.
Assert that actual
matches the RegExp in expected
.
Assert that actual
does not match the RegExp in expected
.
Assert that haystack
contains needle
. For strings and arrays, this asserts that indexOf
returns a value other than -1
. For objects, this method asserts that needle
is the name of a property on haystack
.
Assert that haystack
does not contain needle
. See assert.includes.
Assert that value.length === expected
.
Assert that actual < expected
.
Assert that actual <= expected
.
Assert that actual > expected
.
Assert that actual >= expected
.
Assert is a fork of Procliam, licensed under the MIT license.