1 | # bond ![build status](https://travis-ci.org/EndangeredMassa/bond.png) [![David](https://david-dm.org/EndangeredMassa/bond.png)](https://david-dm.org/EndangeredMassa/bond)
|
2 |
|
3 | _the simple stub/spy javascript library_
|
4 |
|
5 | bond only provides stubbing and spy functionality.
|
6 | For test running and assertions,
|
7 | you will need to use other libraries.
|
8 |
|
9 | This project is a safe and inclusive place
|
10 | for contributors of all kinds.
|
11 | See the [Code of Conduct](CODE_OF_CONDUCT.md)
|
12 | for details.
|
13 |
|
14 |
|
15 | ## bond api
|
16 |
|
17 | `bond(object, 'propertyOrMethodName')` returns the bond api
|
18 |
|
19 | `bond()` returns an anonymous spy
|
20 |
|
21 | `bond().return(value)` returns an anonymous spy that returns the given value when called
|
22 |
|
23 | `bond#to(value)` replaces the value with a new value; reverts the stub after the current test completes
|
24 |
|
25 | `bond#return(value)` replaces the value with a spy that returns the given value; reverts the spy after the current test completes
|
26 |
|
27 | `bond#asyncReturn(values...)` replaces the value with a spy that calls the last argument passed to the function with the provided values
|
28 |
|
29 | `bond#through()` replaces the value with a spy, but allows it to return its normal value
|
30 |
|
31 | `bond#restore()` replaces a spy/stub with its original value; useful for implementing your own `cleanup` handler (see below)
|
32 |
|
33 | ### bond spies
|
34 |
|
35 | `spy.called` is a call count for the spy
|
36 |
|
37 | `spy.calledWith(arg1, arg2, ...)` is a test for being called with specific values
|
38 |
|
39 | `spy.calledArgs` is an array of methods calls, each index holds the array of arguments for that call
|
40 |
|
41 | ## usage
|
42 |
|
43 | `npm install bondjs` -> `bond = require 'bondjs'`
|
44 |
|
45 | **with mocha, qunit, jasmine**: These frameworks should work with bond as is. Bond looks for a global function named either `afterEach` or `testDone` to implement its spy/stub restore functionality. If those exist, as they should when using these frameworks, it should work fine.
|
46 |
|
47 | **with some other test runner**: You may need to implement your own `cleanup` method for bond to work properly. This might look like the following.
|
48 |
|
49 | `bond.cleanup = someTestRunner.registerAfterCallback`
|
50 |
|
51 | ## tests
|
52 |
|
53 | see the `test.coffee` file for examples
|
54 |
|
55 | use `npm test` to run the tests
|
56 |
|
57 | ## license
|
58 |
|
59 | [MIT](LICENSE)
|
60 |
|