Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Test doubles for asynchronous JavaScript that are easy on the eyes.
CoffeeScript JavaScript Shell

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
node_modules/chai
src
test
.gitignore
.travis.yml
LICENCE
README.md
build.sh
grunt.js
ideas.js
package.json
publish_patch.sh
spotify_library_sample.js
watch

README.md

Beautiful Lies

Test doubles for asynchronous JavaScript that are easy on the eyes.

Create a test double ...

var db = create_liar([{
  function_name: 'connect',
  on_promise_done: [{
    function_name: 'query',
    promise_fail_value: {
      message: 'The query timed out.'
    }
  }]
}])

And call it ...

db.connect().done(function() {
  db.query().fail(function(error) {
    console.log(error.message); // <-- Will output 'The query timed out.'
  })
})

Syntax

Liars are generated using a basic hierarchial JSON-based language, that has three basic types of building blocks - expectations specs, result specs and callback specs:

Expectation spec

{
  function_name: 'collection',
  arguments: [ 'members' ],
  returns: /* RESULT SPEC GOES HERE */
  run_function: function() {
    // anything you want here.
  }
  run_callback: /* ARRAY OF CALLBACK SPECS GOES HERE */
  run_callback_flow: /* ARRAY OF CALLBACK SPECS GOES HERE*/
}

Result spec

{
  value: { someProperty: 5 }
  on_value: /* ARRAY OF EXPECTATION SPECS GOES HERE */
},

Callback spec

{
  argument_1: /* RESULT SPEC GOES HERE */
  argument_2: /* RESULT SPEC GOES HERE*/,
  of:
    function_name: 'addEventListener'
    arguments: [ 'click' ]
  delay: 1000
}

Plugins

Expectations, results and callback object are buildings blocks that can be used to construct plugins (on_promise_done is a plugin, for instance). Check out the built in plugins here, for inspiration: https://github.com/mpj/beautiful-lies/blob/master/plugins.coffee

Something went wrong with that request. Please try again.