spok

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.

spok(t: Object, obj: Object, specifications: Object)
Parameters
t (Object) which has assertion functions equal and deepEqual (to compare objects) - use tap , tape , assert or any other library that has those and thus is compatible
obj (Object) the object to verify the specifications against
specifications (Object) the specifications to verify

spok.range

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
}
spok.range(min: Number, max: Number)
Parameters
min (Number) minimum
max (Number) maximum

spok.gt

Specififies that a number is greater than the given criteria.

var spec = {
 x: spok.gt(1)  // specifies that x should be >1
}
spok.gt(n: Number)
Parameters
n (Number) criteria

spok.ge

Specififies that a number is greater or equal the given criteria.

var spec = {
 x: spok.ge(1)  // specifies that x should be >=1
}
spok.ge(n: Number)
Parameters
n (Number) criteria

spok.lt

Specififies that a number is less than the given criteria.

var spec = {
 x: spok.lt(1)  // specifies that x should be < 1
}
spok.lt(n: Number)
Parameters
n (Number) criteria

spok.le

Specififies that a number is less or equal the given criteria.

var spec = {
 x: spok.le(1)  // specifies that x should be <=1
}
spok.le(n: Number)
Parameters
n (Number) criteria

spok.ne

Specifies that the value is not equal another.

var spec = {
 x: spok.ne(undefined)  // specifies that x should be defined
}
spok.ne(value: Any)
Parameters
value (Any) criteria

spok.gtz

Specifies that the value is greater than zero

var spec = {
  x: spok.gtz
}
spok.gtz()

spok.gez

Specifies that the value is greater or equal zero

var spec = {
  x: spok.gez
}
spok.gez()

spok.ltz

Specifies that the value is less than zero

var spec = {
  x: spok.ltz
}
spok.ltz()

spok.lez

Specifies that the value is less or equal zero

var spec = {
  x: spok.lez
}
spok.lez()

spok.type

Specifies that the input is of a given type.

var spec = {
 x: spok.type('number')  // specifies that x should be a Number
}
spok.type(t: String)
Parameters
t (String) expected type

spok.array

Specifies that the input is an array.

var spec = {
 x: spok.array  // specifies that x should be an Array
}
spok.array()

spok.arrayElements

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 }

spok.arrayElements(n: Number)
Parameters
n (Number) number of elements

spok.arrayElementsRange

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 }

spok.arrayElementsRange(min: Number, max: Number)
Parameters
min (Number) min number of elements
max (Number) max number of elements

spok.number

Specifies that the input of type number and isNaN(x) returns false.

var spec = {
 x: spok.number  // specifies that x should be a Number
}
spok.number()

spok.string

Specifies that the input is a string.

var spec = {
  x: spok.string  // specifies that x should be a String
}
spok.string()

spok.function

Specifies that the input is a function.

var spec = {
  x: spok.function  // specifies that x should be a function
}
spok.function()

spok.definedObject

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
}
spok.definedObject()

spok.startsWith

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'
}
spok.startsWith(what: String)
Parameters
what (String) substring the given string should start with

spok.endsWith

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'
}
spok.endsWith(what: String)
Parameters
what (String) substring the given string should start with

spok.test

Specifies that the string needs to match the given regular expression.

var spec = {
  x: spok.test(/hello$/) // specifies that x should match /hello$/
}
spok.test(regex: RegExp)
Parameters
regex (RegExp) regular expression against which the string is checked via test

spok.defined

Specifies that a value is defined, i.e. it is neither null nor undefined.

var spec = {
  x: spok.defined
}
spok.defined()

spok.notDefined

Specifies that a value is notDefined, i.e. it is either null or notDefined.

var spec = {
  x: spok.notDefined
}
spok.notDefined()