Skip to content

Commit

Permalink
pattern(mock): improve examples of mock use
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellmb committed Sep 14, 2013
1 parent 198c72b commit f7b60c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion example/coffeescript/scenario.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe 'My App', ->
browser().navigateTo '#/'

it 'should contain expected text', ->
expect(element('[ng-view] p:first').text()).toBe 'this is the home page.'
expect(element('[ng-view] p:first')
.text()).toBe 'this is the home page.'

# CoffeeScript
describe 'my view', ->
Expand Down
20 changes: 12 additions & 8 deletions patterns/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Because AngularJS removes hard-coded dependencies via injection it's possible to

### How to use mocks

Using mocks in AngularJS is as easy as `providing` them. **Note**: This must be done *before* the code under test is injected.
Using mocks in AngularJS is as easy as providing them. Note that this must be done *before* the code under test is injected. Order matters:

1. First `provide` your mocks to override the real implementation.
2. Then `inject` the mock with the rest of your code under test.
3. Finally `assert` that the code under test is interacting with the mock correctly.

[Controller Testing Patterns](controller.md) has a full example of [providing and injecting](controller.md#suggested-controller-unit-test-setup-) a [mock](../example/coffeescript/mock.coffee) then [asserting its use](controller.md#call-mymethod-on-mysvc-) against an [example application](../example/coffeescript/app.coffee).

####Examples
```CoffeeScript
Expand Down Expand Up @@ -32,13 +38,11 @@ beforeEach(function () {
```


###### [Example](../example) mock implementations

Mocks allow you to unit test you are interacting with a dependency correctly. They enable you to control the context and answer questions such as:

### Is my code:
### Is my code...

* calling a dependency method when it should
* passing the correct value(s) to that method
* handling dependency errors
* cleaning up properly afterword
* calling a dependency method when it should?
* passing the correct value(s) to that method?
* handling dependency errors?
* cleaning up properly afterward?

0 comments on commit f7b60c0

Please sign in to comment.