UNPKG

nisemono

Version:

Pretty simple test double library

93 lines (70 loc) 3.82 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>obj.js - Documentation</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.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Call.html">Call</a></li><li><a href="Expectation.html">Expectation</a><ul class='methods'><li data-type='method'><a href="Expectation.html#withArgs">withArgs</a></li><li data-type='method'><a href="Expectation.html#returns">returns</a></li><li data-type='method'><a href="Expectation.html#throws">throws</a></li><li data-type='method'><a href="Expectation.html#resolves">resolves</a></li><li data-type='method'><a href="Expectation.html#rejects">rejects</a></li><li data-type='method'><a href="Expectation.html#calls">calls</a></li></ul></li><li><a href="FakeFunction.html">FakeFunction</a><ul class='methods'><li data-type='method'><a href="FakeFunction.html#callArgFuncAt">callArgFuncAt</a></li></ul></li></ul><h3>Namespaces</h3><ul><li><a href="promise.html">promise</a><ul class='methods'><li data-type='method'><a href="promise.html#.constructor">constructor</a></li><li data-type='method'><a href="promise.html#.use">use</a></li><li data-type='method'><a href="promise.html#.restoreDefault">restoreDefault</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#expects">expects</a></li><li><a href="global.html#func">func</a></li><li><a href="global.html#obj">obj</a></li></ul> </nav> <div id="main"> <h1 class="page-title">obj.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>var func = require('./func'); var util = require('./util'); var isFunc = util.isFunc; var contains = util.contains; var keys = util.keys; /** * Create a fake object. * The fake object has cloned properties and cloned methods or fake methods: * - The methods in `except` options are copied to the fake object from original object. * - The methods in `only` options are fake functions. * - As default, All methods are fake functions. * @param {Object} object a fake object * @param {string[]?} opts.except method name list. the methods of a object are not fake function, use original method. * @param {string[]?} opts.only method name list. The methods of a object are fake function instead of original method. * @return {Object} a fake object */ var obj = function(object, opts) { var key; var fake = {}; var options = opts || {}; var except = options.except || []; var only = options.only || keys(object); for (key in object) { if (isFunc(object[key]) &amp;&amp; !contains(key, except) &amp;&amp; contains(key, only)) { fake[key] = func(); } else { fake[key] = object[key]; } } return fake; }; module.exports = obj; </code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Jan 29 2017 08:56:25 GMT+0900 (JST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>