@@ -20,7 +20,7 @@ sending a pull request for [this issue](https://github.com/testdouble/testdouble
20
20
21
21
The easiest way to create a test double function is to make one anonymously:
22
22
23
- ```
23
+ ``` javascript
24
24
var td = require (' testdouble' );
25
25
var myTestDouble = td .create ();
26
26
```
@@ -32,7 +32,7 @@ In the above, `myTestDouble` will be able to be stubbed or verified as shown bel
32
32
For slightly easier-to-understand error messages (with the trade-off of greater
33
33
redundancy in your tests), you can supply a string name to ` create `
34
34
35
- ```
35
+ ``` javascript
36
36
var myNamedDouble = td .create (" #foo" );
37
37
```
38
38
@@ -66,22 +66,22 @@ respectively.
66
66
67
67
To stub values with testdouble.js, first create one:
68
68
69
- ```
69
+ ``` javascript
70
70
var td = require (' testdouble' );
71
71
myTestDouble = td .create ();
72
72
```
73
73
74
74
You can stub a no-arg invocation like so:
75
75
76
- ```
76
+ ``` javascript
77
77
td .when (myTestDouble ()).thenReturn (" HEY" );
78
78
79
79
myTestDouble (); // returns "HEY"
80
80
```
81
81
82
82
You can stub a specific set of args (performs lodash's ` _.isEqual ` on each) with:
83
83
84
- ```
84
+ ``` javascript
85
85
td .when (myTestDouble (' a' , 5 , {foo: ' bar' })).thenReturn (" YES" );
86
86
87
87
myTestDouble (' a' , 5 , {foo: ' bar' }); // returns "YES"
@@ -102,15 +102,15 @@ you can use the `verify` function.
102
102
103
103
First, create a test double:
104
104
105
- ```
105
+ ``` javascript
106
106
var td = require (' testdouble' );
107
107
var myTestDouble = td .create ();
108
108
```
109
109
110
110
Now, suppose you've passed this function into your [ subject] ( https://github.com/testdouble/contributing-tests/wiki/Subject )
111
111
and you want to verify that it was called with the arguments ` ("foo", 5) ` :
112
112
113
- ```
113
+ ``` javascript
114
114
subject .callTheThingThatShouldBeInvokingMyTestDouble ()
115
115
116
116
td .verify (myTestDouble (" foo" , 5 ))
@@ -146,7 +146,7 @@ You can see the built-in matchers in the [source](https://github.com/testdouble/
146
146
147
147
Here's an example usage of the provided ` isA() ` matcher:
148
148
149
- ```
149
+ ``` javascript
150
150
var td = require (' testdouble' );
151
151
var myTestDouble = td .create ();
152
152
@@ -160,7 +160,7 @@ myTestDouble(new String("neato")) // returns "YES"
160
160
161
161
Matchers can also be used to relax or augment the ` verify() ` method, like so:
162
162
163
- ```
163
+ ``` javascript
164
164
verify (myTestDouble (td .matchers .isA (Date )))
165
165
```
166
166
@@ -223,13 +223,13 @@ you may choose to make a few of the top-level functions global in a test helper
223
223
224
224
Perhaps you want to keep everything namespaced under ` td` for short:
225
225
226
- ` ` `
226
+ ` ` ` javascript
227
227
global .td = require (' testdouble' );
228
228
` ` `
229
229
230
230
Or, you might prefer to plop the methods directly on the global:
231
231
232
- ` ` `
232
+ ` ` ` javascript
233
233
global .double = require (' testdouble' ).create ;
234
234
global .when = require (' testdouble' ).when ;
235
235
global .verify = require (' testdouble' ).verify ;
0 commit comments