Beautiful Lies
Mocks for asynchronous JavaScript that are easy on the eyes. Yay! Hooray! Fnuff.
Create a test double ...
var beautiful = beautiful var db = {}db
And call it ...
db
Syntax
Liars are generated using a simple, hierarchial JSON-based DSL, that has three basic types of building specifications: expectations, results and callbacks.
Expectation specification
function_name: 'collection' arguments: 'members' { return true } returns: /* RESULT SPEC GOES HERE */ { // anything you want here. } run_callback: /* ARRAY OF CALLBACK SPECS GOES HERE */ run_callback_flow: /* ARRAY OF CALLBACK SPECS GOES HERE*/
Result specification
self: false value: someProperty: 5 on_value: /* ARRAY OF EXPECTATION SPECS GOES HERE */
Callback specification
property_xxxx: /* RESULT SPEC GOES HERE */ argument_1: /* RESULT SPEC GOES HERE */ argument_2: /* RESULT SPEC GOES HERE*/ of: function_name: 'addEventListener' arguments: 'click' delay: 1000
Macros
Expectations, results and callback object are buildings blocks that can be used to construct macros (on_promise_done is a plugin, for instance). Check out the built-in macros here, for inspiration: https://github.com/mpj/beautiful-lies/blob/master/src/macros.coffee