whatever.js
v0.1.0
Published
Whatevs, dude
Downloads
6
Maintainers
Readme
whatever.js
This library lets you define objects that dynamically define properties as you try to access them (using ES6 Proxies). Its main use case is tests where you want to mock services without going to the trouble of setting up objects with the correct schema.
For example, instead of this...
stub(service).return({
user: {
firstName: 'joe',
lastName: 'schmoe',
email: '[email protected]'
},
items: [
{ id: 1, type: 'woozle', name: 'foo' },
{ id: 2, type: 'wuzzle', name: 'bar' }
],
summary: {
user: 'joe schmoe <[email protected]>',
woozles: 1,
wuzzles: 1
}
});
...with whatever.js you can just go with this:
var whatever = require('whatever.js');
stub(service).return(whatever());
You can also specify defaults for only the properties you care about (e.g., for testing). Accesses to any other properties of the resulting object will just silently do nothing.
stub(service).return(whatever({
user: {
firstName: 'Billy'
}
}));
assert.equal(greetUser(), 'Hello, Billy');