2018-05-03 11:20:13 +02:00
|
|
|
/**
|
|
|
|
* assertionHandler.mjs
|
|
|
|
*
|
|
|
|
* Pair native node assertions with a description for
|
|
|
|
* the benefit of the TestRegister.
|
|
|
|
*
|
|
|
|
* @author d98762625 [d98762625@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2018
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-06-15 12:33:13 +02:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-18 12:17:54 +02:00
|
|
|
* Print useful stack on error
|
2018-06-15 12:33:13 +02:00
|
|
|
*/
|
|
|
|
const wrapRun = (run) => () => {
|
|
|
|
try {
|
|
|
|
run();
|
|
|
|
} catch (e) {
|
|
|
|
console.dir(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-03 11:20:13 +02:00
|
|
|
/**
|
|
|
|
* it - wrapper for assertions to provide a helpful description
|
|
|
|
* to the TestRegister
|
2018-05-11 12:09:04 +02:00
|
|
|
* @namespace ApiTests
|
2018-05-03 11:20:13 +02:00
|
|
|
* @param {String} description - The description of the test
|
|
|
|
* @param {Function} assertion - The test
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // One assertion
|
|
|
|
* it("should run one assertion", () => assert.equal(1,1))
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // multiple assertions
|
|
|
|
* it("should handle multiple assertions", () => {
|
|
|
|
* assert.equal(1,1)
|
|
|
|
* assert.notEqual(3,4)
|
|
|
|
* })
|
2018-05-03 14:58:15 +02:00
|
|
|
*
|
2018-05-03 11:20:13 +02:00
|
|
|
* @example
|
|
|
|
* // async assertions
|
|
|
|
* it("should handle async", async () => {
|
|
|
|
* let r = await asyncFunc()
|
|
|
|
* assert(r)
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
export function it(name, run) {
|
|
|
|
return {
|
|
|
|
name,
|
2018-06-15 12:33:13 +02:00
|
|
|
run: wrapRun(run),
|
2018-05-03 11:20:13 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default it;
|