mocktail-js

1.9.5 • Public • Published

build dependencies npm package vulnerabilities

A JavaScript library that takes the pain out of mocking deep objects.

Installation

Install the package with npm:

npm install mocktail-js

Include it in your project:

import mocktail from "mocktail-js";

Documentation

MocktailJS builds a JavaScript object off of a string pattern. The deepest keys may be assigned values, left to right, based on the passed pattern.

Mock deep object

Use period character to indicate parent-child relation.

mocktail("foo.bar.baz", 123);
 
/*
 *  Returned object:
 *  
 *  {
 *      foo: {
 *          bar: {
 *              baz: 123
 *          }
 *      }
 *  }
 */

Mock deep and wide object

Use comma character to indicate sibling relations.

function getStuff() { return "stuff"; }
 
mocktail("foo.bar,boo.baz", null, getStuff);
 
/*
 *  Returned object:
 *  
 *  {
 *      foo: {
 *          bar: null
 *      },
 *      boo: {
 *          baz: getStuff
 *      }
 *  }
 */

Mock deep and wide object with forks

Use colon character to indicate forking and semicolon to terminate it.

mocktail("foo.bar,boo:baz.one,ban.two.three;", 123, null, "awesome");
 
/*
 *  Returned object:
 *  
 *  {
 *      foo: {
 *          bar: 123
 *      },
 *      boo: {
 *          baz: {
 *              one: null
 *          },
 *          ban: {
 *              two: {
 *                  three: "awesome"
 *              }
 *          }
 *      }
 *  }
 */

License

MIT

Package Sidebar

Install

npm i mocktail-js

Weekly Downloads

1

Version

1.9.5

License

MIT

Unpacked Size

46.4 kB

Total Files

25

Last publish

Collaborators

  • jakubbarczyk