1.9.5 • Published 2 years ago

mocktail-js v1.9.5

Weekly downloads
21
License
MIT
Repository
github
Last release
2 years ago

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

1.9.5

2 years ago

1.9.4

4 years ago

1.9.3

5 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.2

7 years ago

1.8.1

7 years ago

1.8.0

8 years ago

1.7.9

8 years ago

1.7.6

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.3.6

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago