Use simple unit test utils in tape:
- @param { Mixed } value
- @param { String } message
Check that value
is true
.
t.isTrue(true, 'should be true')
- @param { Mixed } value
- @param { String } message
Check that value
is false
.
t.isFalse(false, 'should be false')
- @param { Mixed } value
- @param { String } name
- @param { String } message
Check that value
’s type is name
, as determined by Object.prototype.toString
.
t.typeOf({foo: 1, bar: 2}, 'object', 'should be an object')
t.typeOf([1, 2, 3], 'array', 'should be an array')
t.typeOf('foo', 'string', 'should be a string')
t.typeOf(1, 'number', 'should be a number')
t.typeOf(true, 'boolean', 'should be boolean')
t.typeOf(/^foo/, 'regexp', 'should be a regular expression')
t.typeOf(new Date(), 'date', 'should be a date')
t.typeOf(null, 'null', 'should be a null')
t.typeOf(undefined, 'undefined', 'should be an undefined')
- @param { Mixed } value
- @param { String } typeof name
- @param { String } message
Check that value
’s type is not name
, as determined by Object.prototype.toString
.
t.notTypeOf('tea', 'number', 'string should not be number')
- @param { Number } val1
- @param { Number } val2
- @param { String } message
Check that val1
is less then val2
.
t.isLess(1, 2, '1 should be less then 2')
- @param { Number } val1
- @param { Number } val2
- @param { String } message
Check that val1
is greater then val2
.
t.isMore(2, 1, '2 should be greater then 1')
- @param { Object } value
- @param { Constructor } constructor
- @param { String } message
Check that value
is an instance of constructor
.
t.instanceOf(new Date(), Date, 'should be instance of Date')
- @param { Object } value
- @param { Constructor } constructor
- @param { String } message
Check that value
is not an instance of constructor
.
t.notInstanceOf(new Date(), String, 'should not be an instance of String')
- @param { Object } value
- @param { String } message
Check that value
is an empty object.
t.isEmpty({}, 'object should be empty')
t.isEmpty([], 'array should be empty')
t.isEmpty('', 'string should be empty')
- @param { Object } value
- @param { String } message
Check that value
is not an empty object.
t.isNotEmpty(object, 'object should not be empty')
t.isNotEmpty(array, 'array should not be empty')
t.isNotEmpty('foo', 'string should not be empty')
- @param { Mixed } value
- @param { String } message
Check that value
is an object of type 'Object'
(as revealed by Object.prototype.toString
).
t.isObject({foo: 1, bar: 2}, 'should be object')
- @param { Mixed } value
- @param { String } message
Check that value
is not an object of type 'Object'
(as revealed by Object.prototype.toString
).
t.isNotObject('object', 'should not be object')
- @param { Mixed } value
- @param { String } message
Check that value
is an array
.
t.isArray([1, 2, 3], 'should be array')
- @param { Mixed } value
- @param { String } message
Check that value
is not an array
.
t.isNotArray('foo', 'should not be array')
- @param { Mixed } value
- @param { String } message
Check that value
is a string
.
t.isString('foo', 'should be string')
- @param { Mixed } value
- @param { String } message
Check that value
is not a string
.
t.isNotString({foo: 1}, 'should not be string')
- @param { Mixed } value
- @param { String } message
Check that value
is a number
.
t.isNumber(1, 'should be number')
- @param { Mixed } value
- @param { String } message
Check that value
is not a number
.
t.isNotNumber('1', 'should not be number')
- @param { Mixed } value
- @param { String } message
Check that value
is a boolean
.
t.isNumber(true, 'should be boolean')
- @param { Mixed } value
- @param { String } message
Check that value
is not a boolean
.
t.isNotNumber('true', 'should not be boolean')
- @param { Mixed } value
- @param { String } message
Check that value
is null
.
t.isNull(null, 'should be null')
- @param { Mixed } value
- @param { String } message
Check that value
is not null
.
t.isNotNull(NaN, 'should not be null')
- @param { Mixed } value
- @param { String } message
Check that value
is NaN
.
t.isNaN(NaN, 'should be NaN')
- @param { Mixed } value
- @param { String } message
Check that value
is not NaN
.
t.isNotNaN(null, 'should not be NaN')
- @param { Mixed } value
- @param { String } message
Check that value
is undefined
.
let foo
t.isUndefined(foo, 'should be undefined')
- @param { Mixed } value
- @param { String } message
Check that value
is not undefined
.
let tea = 'some tea';
t.isDefined(tea, 'tea should be defined')
- @param { Mixed } value
- @param { String } message
Check that value
is a function
.
const log = (...argv) => console.log(...argv)
t.isFunction(log, 'log should be function')
- @param { Mixed } value
- @param { String } message
Check that value
is not a function
.
const foo = 'foo'
t.isNotFunction(foo, 'foo should not be function')
- @param { Array | String } haystack
- @param { Mixed } needle
- @param { String } message
Check that haystack
includes needle
. Works for strings
and arrays
.
t.include('foobar', 'bar', 'foobar should include "bar"')
t.include([1, 2, 3], 3, 'array should include 3')
- @param { Array | String } haystack
- @param { Mixed } needle
- @param { String } message
Check that haystack
does not include needle
. Works for strings
and arrays
.
assert.notInclude('foobar', 'baz', 'string should not include substring')
assert.notInclude([1, 2, 3], 4, 'array should not include contain value')
- @param { Mixed } value
- @param { RegExp } regexp
- @param { String } message
Check that value
matches the regular expression regexp
.
assert.match('foobar', /^foo/, 'regexp should match')
- @param { Mixed } value
- @param { RegExp } regexp
- @param { String } message
Check that value
does not match the regular expression regexp
.
t.notMatch('foobar', /^foo/, 'regexp should not match')
- @param { Object } object
- @param { String } property
- @param { String } message
Check that object
has a property named by property
.
t.property({foo: 'foo'}, 'foo', 'should have property "foo"')
@param { Object } object @param { String } property @param { String } message
Check that object
does not have a property named by property
.
t.notProperty({foo: 'foo'}, 'bar', 'should not have property "bar"')
- @param { Mixed } val1
- @param { String } operator
- @param { Mixed } val2
- @param { String } message
Check two values
using operator
.
t.operator(1, '<', 2, 'should be 1 < 2')
t.operator(3, '>', 2, 'should be 3 > 2')
t.operator(3, '>=', 2, 'should be 3 >= 2')
t.operator(2, '<=', 2, 'should be 2 <= 2')
t.operator(1, '==', 1, 'should be 1 == 1')
t.operator(1, '!=', 2, 'should be 1 != 2')
t.operator(1, '===', 1, 'should be 1 === 1')
- @param { Number } actual
- @param { Number } expected
- @param { Number } delta
- @param { String } message
Check that the target
is equal to expected
, to within a +/-
delta
range.
t.closeTo(1.5, 1, 0.5, 'numbers should be close')
- @param { Array } set1
- @param { Array } set2
- @param { String } message
Check that set1
and set2
have the same members
. Order is not taken into account.
t.sameMembers([1, 2, 3], [2, 1, 3], 'should be same members')
- @param { Array } superset
- @param { Array } subset
- @param { String } message
Check that subset
is included in superset
. Order is not taken into account.
t.includeMembers([1, 2, 3], [2, 1], 'should include members')
- @param { } inList
- @param { Array.<*> } list
- @param { String } message
Check that non-object, non-array value inList
appears in the flat array list
.
t.oneOf(1, [1, 2, 3], 'should be in array')