Skip to content

Commit 5c82051

Browse files
committed
readme fix
1 parent 099911d commit 5c82051

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

README.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ original(); //returns 'realValue'
4444
```
4545

4646
Note: Consumers do not need to provide a `thisArg`. It is optional and only used to force a specific `this` when the original fallback is called (low-level partial mock usage).
47+
Mocking an object
48+
-----------------
49+
__Partial object mock__
50+
51+
```js
52+
function newCustomer(_name) {
53+
var c = {};
54+
55+
c.getName = function ()
56+
{
57+
return _name;
58+
};
59+
60+
return c;
61+
}
62+
63+
var customer = newCustomer('Alfonzo The Real');
64+
var customerMock = mock(customer);
65+
66+
customerMock.getName.expect().return('Johnny Fake');
67+
68+
customer.getName(); //returns Johnny Fake
69+
customer.getName(); //returns Alfonzo The Real
70+
customerMock.verify(); //returns true
71+
```
4772

4873

4974

@@ -355,32 +380,6 @@ requireMock.reset(); //is an alias for expectRequire.reset()
355380
require('./realDep'); //returns realDep
356381

357382
```
358-
Mocking an object
359-
-----------------
360-
__Partial object mock__
361-
362-
```js
363-
function newCustomer(_name) {
364-
var c = {};
365-
366-
c.getName = function ()
367-
{
368-
return _name;
369-
};
370-
371-
return c;
372-
}
373-
374-
var customer = newCustomer('Alfonzo The Real');
375-
var customerMock = mock(customer);
376-
377-
customerMock.getName.expect().return('Johnny Fake');
378-
379-
customer.getName(); //returns Johnny Fake
380-
customer.getName(); //returns Alfonzo The Real
381-
customerMock.verify(); //returns true
382-
```
383-
384383
Mocking promises
385384
-----------------
386385
__Mocking resolve__

0 commit comments

Comments
 (0)