3.3.3 • Published 10 years ago

beautiful-lies v3.3.3

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Beautiful Lies

Build status Dependency status Dependency (dev) status

Mocks for asynchronous JavaScript that are easy on the eyes. Yay! Hooray! Fnuff.

Create a test double ...

var beautiful = require('beautiful-lies')
    beautiful.lie()

var db = {}
db.lie({
  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 simple, hierarchial JSON-based DSL, that has three basic types of building specifications: expectations, results and callbacks.

Expectation specification

{
  function_name: 'collection',
  arguments: [ 'members' ],
  check: function() { return true },
  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 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

3.3.3

10 years ago

3.3.2

10 years ago

3.3.1

10 years ago

3.3.0

11 years ago

3.2.1

11 years ago

3.2.0

11 years ago

3.1.1

11 years ago

3.1.0

11 years ago

3.0.0

11 years ago

2.0.0

11 years ago

1.0.10

11 years ago

1.0.9

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

12 years ago

1.0.0

12 years ago

0.2.9

12 years ago

0.2.8

12 years ago

0.2.7

12 years ago

0.2.6

12 years ago

0.2.5

12 years ago

0.2.4

12 years ago