UNPKG

semtest

Version:

NodeJs Unit test framework combining Tape, Proxyquire and Sinon

1,199 lines (344 loc) 14.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Module: Library/Test-Helpers</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Module: Library/Test-Helpers</h1> <section> <header> </header> <article> <div class="container-overview"> <div class="description"><h3>Test helpers</h3><p>This module hosts everything needed for tests. Abstraction over the expection engine, abstraction over the basic functions, this module is the Test toolbelt. Little to no test framework logic should be in unit tests to keep them focused on code documentation.</p></div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line1">line 1</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id=".convertIntoComputedProperties"><span class="type-signature">(static) </span>convertIntoComputedProperties<span class="signature">(dictionnary, object)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Convert an object into another object with computed properties by using the given object properties names as keys declared in the given dependency dictionnary. If they are not defined, this function will assume that they refer to node modules instead of project-related ones during the computed property resolution. Usage of the dictionnary is optional, but helpful since you can then use aliases for modules names in your stubs declaration, instead of having to resolve all modules path names (since proxyquire need them)</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>dictionnary</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Dictionnary</p></td> </tr> <tr> <td class="name"><code>object</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Input object</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line173">line 173</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Converted object</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id=".executeTestsInternal"><span class="type-signature">(static) </span>executeTestsInternal<span class="signature">(mode, moduleName, assertions)</span><span class="type-signature"> &rarr; {Array}</span></h4> <div class="description"> <p>Returns a function that will perform several tests, each with a concatenated description. Descriptions will be concatenated to form a test statement that will have this structure: &quot;Module - Function(): When XXXXXXXXX, it should YYYYYYYYY</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>mode</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>Execution mode(null = normal, skip, or only)</p></td> </tr> <tr> <td class="name"><code>moduleName</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>Tested module description</p></td> </tr> <tr> <td class="name"><code>assertions</code></td> <td class="type"> <span class="param-type">Array.&lt;Object></span> </td> <td class="description last"><p>Assertion array to perform</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line50">line 50</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Assertions execution results</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id=".prepareForTests"><span class="type-signature">(static) </span>prepareForTests<span class="signature">(dictionnary, defaultStubs, testFileName, customStubs)</span><span class="type-signature"> &rarr; {Mixed}</span></h4> <div class="description"> <p>Prepare a module for tests by requiring it with stubs Module name is based on the given test file name that will consume the prepared module.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>dictionnary</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Dictionnary</p></td> </tr> <tr> <td class="name"><code>defaultStubs</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Default stubs (internal dependencies) of the tested module</p></td> </tr> <tr> <td class="name"><code>testFileName</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>Test file name</p></td> </tr> <tr> <td class="name"><code>customStubs</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Custom stubs for the proxified module</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line219">line 219</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Proxified module</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Mixed</span> </dd> </dl> <h4 class="name" id=".requireWithStubs"><span class="type-signature">(static) </span>requireWithStubs<span class="signature">(dictionnary, defaultStubs, moduleName, customStubs)</span><span class="type-signature"> &rarr; {Mixed}</span></h4> <div class="description"> <p>Require a module with stubbed dependencies</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>dictionnary</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Dictionnary</p></td> </tr> <tr> <td class="name"><code>defaultStubs</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Default stubs (internal dependencies) of the tested module</p></td> </tr> <tr> <td class="name"><code>moduleName</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>Module name to proxiquire</p></td> </tr> <tr> <td class="name"><code>customStubs</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Custom stubs for the proxified module</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line197">line 197</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Proxified module</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Mixed</span> </dd> </dl> <h4 class="name" id=".unitTest"><span class="type-signature">(static) </span>unitTest<span class="signature">(testFn, testDescription, cb)</span><span class="type-signature"> &rarr; {function}</span></h4> <div class="description"> <p>Return a function that will execute a test with a given description</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>testFn</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>Test engine</p></td> </tr> <tr> <td class="name"><code>testDescription</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last"><p>Unit test description</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>Callback called with test engine object</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="main.js.html">main.js</a>, <a href="main.js.html#line36">line 36</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Unit test handler</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">function</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Library_Test-Helpers.html">Library/Test-Helpers</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.1</a> on Tue Sep 27 2016 08:05:15 GMT+0200 (CEST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>