lab-testing
Installation
npm install lab-testing --save-dev
lab-testing contains two namespaces: throws
and rejects
. The contain the same tests with throws
used to test synchronous messages and rejects
used to test promises. In addition, there are a few top levels tests too.
See Change Log for changes from previous versions. As of version 3.0.0 the minimum version of lab that this package is compatible with is 15.0.0.
Standard Constructor Test
Executes basic tests for nulls and undefined against all constructor parameters.
Parameters:
- class: Class - The class to instantiate
- labels: string[] - description of the parameters for the constructor
- parameters: ...params - The correct values for the constructor
;;; const lab = exportslab = Lab;const testing = ; lab;
Destructured Constructor Test
Executes basic tests for nulls and undefined against all constructor object properties.
Parameters:
- class: Class - The class to instantiate
- validParam: Object - a valid argument object
;;; const lab = exportslab = Lab;const testing = ; lab;
Create Experiment
Sometimes you want to represent hierarchy in your tests which, with lab, means a lot of indenting. This just reduces that indent and eliminates the boilerplate code.
Parameters:
- ...levels: string[] - Any number of levels as strings
;;; const lab = exportslab = Lab;const expect = Codeexpect;const testing = ; const group = testing; ;
The created function also supports skip
and only
.
group; group;
Function Parameter Test
Executes basic tests for nulls and undefined against all function parameters.
Parameters:
- function: Function - The function to test
- labels: string[] - description of the parameters for the constructor
- parameters: ...params - The correct values for the constructor
Testing for Thrown Exceptions
;; const lab = exportslab = Lab;const testing = ; lab;
Testing for Rejected Promises
;; const lab = exportslab = Lab;const testing = ; lab;
Function Destructured Parameter Test
Executes basic tests for nulls and undefined against all properties of the function parameter object.
Parameters:
- function: Function - The function to test
- validParam: object - valid argument object to pass to the function
Testing for Thrown Exceptions
;; const lab = exportslab = Lab;const testing = ; lab;
Testing for Rejected Promises
;; const lab = exportslab = Lab;const testing = ; lab;
Method Parameter Test
Executes basic tests for nulls and undefined against all method parameters.
Parameters:
- object: Object - The instance of a class
- function: Function - The method on that instance
- labels: string[] - description of the parameters for the constructor
- parameters: ...params - The correct values for the constructor
Testing for Thrown Exceptions
;; const lab = exportslab = Lab;const testing = ; { // no parameter checks! This will fail some tests return; } lab;
Testing for Rejected Promises
;; const lab = exportslab = Lab;const testing = ; { // no parameter checks! This will fail some tests return { return ; }; } lab;
Method Destructured Parameter Test
Executes basic tests for nulls and undefined against all properties of the method parameter object.
Parameters:
- object: Object - The instance of a class
- function: Function - The method on that instance
- validParam: object - valid argument object to pass to the method
Testing for Thrown Exceptions
;; const lab = exportslab = Lab;const testing = ; { // no parameter checks! This will fail some tests return; } lab;
Testing for Rejected Promises
;; const lab = exportslab = Lab;const testing = ; { // no parameter checks! This will fail some tests return { return ; }; } lab;