Checks the given specifications against the object.
When the tests are run the actual values are printed to verify visually while each provided specification is validated and a test failure caused if one of them fails.
Specififies that the given number is within the given range, i.e. min<= x <=max
.
var spec = {
x: spok.range(1, 2) // specifies that x should be >=1 and <=2
}
Specififies that a number is greater than the given criteria.
var spec = {
x: spok.gt(1) // specifies that x should be >1
}
(Number)
criteria
Specififies that a number is greater or equal the given criteria.
var spec = {
x: spok.ge(1) // specifies that x should be >=1
}
(Number)
criteria
Specififies that a number is less than the given criteria.
var spec = {
x: spok.lt(1) // specifies that x should be < 1
}
(Number)
criteria
Specififies that a number is less or equal the given criteria.
var spec = {
x: spok.le(1) // specifies that x should be <=1
}
(Number)
criteria
Specifies that the value is not equal another.
var spec = {
x: spok.ne(undefined) // specifies that x should be defined
}
(Any)
criteria
Specifies that the value is greater than zero
var spec = {
x: spok.gtz
}
Specifies that the value is greater or equal zero
var spec = {
x: spok.gez
}
Specifies that the value is less than zero
var spec = {
x: spok.ltz
}
Specifies that the value is less or equal zero
var spec = {
x: spok.lez
}
Specifies that the input is of a given type.
var spec = {
x: spok.type('number') // specifies that x should be a Number
}
(String)
expected type
Specifies that the input is an array.
var spec = {
x: spok.array // specifies that x should be an Array
}
Specifies that the input is an array with a specific number of elements
var spec = { x: spok.arrayElements(2) // specifies that x should be an Array with 2 elements }
(Number)
number of elements
Specifies that the input is an array with a number of elements in a given range
var spec = { x: spok.arrayElementsRange(2, 4) // specifies that x should be an Array with 2-4 elements }
Specifies that the input of type number and isNaN(x)
returns false
.
var spec = {
x: spok.number // specifies that x should be a Number
}
Specifies that the input is a string.
var spec = {
x: spok.string // specifies that x should be a String
}
Specifies that the input is a function.
var spec = {
x: spok.function // specifies that x should be a function
}
Specifies that the input is an object and it is not null
.
var spec = {
x: spok.definedObject // specifies that x is a non-null object
}
Specifies that the string starts with the specified substring.
NOTE: only available with node.js which has an ES6 startsWith
function
var spec = {
x: spok.startsWith('hello') // specifies that x should start with 'hello'
}
(String)
substring the given string should start with
Specifies that the string ends with the specified substring.
NOTE: only available with node.js which has an ES6 endsWith
function
var spec = {
x: spok.endsWith('hello') // specifies that x should start with 'hello'
}
(String)
substring the given string should start with
Specifies that the string needs to match the given regular expression.
var spec = {
x: spok.test(/hello$/) // specifies that x should match /hello$/
}
Specifies that a value is defined, i.e. it is neither null
nor undefined
.
var spec = {
x: spok.defined
}
Specifies that a value is notDefined, i.e. it is either null
or notDefined
.
var spec = {
x: spok.notDefined
}