docs(tutorial/step-2): add beforeEach to load module

The non-global controller test throws an error because the test does not
know about the module and so can not find the controller. This change
tells the test about the module so the test can find the controller.

Closes #4489
This commit is contained in:
DanS 2013-10-17 07:05:28 -07:00 committed by Pete Bacon Darwin
parent 280354c3f9
commit c1e6afca11

View file

@ -151,13 +151,15 @@ Angular. Since testing is such a critical part of software development, we make
tests in Angular so that developers are encouraged to write them.
### Testing non-Global Controllers
In practice, you will not want to have your controller functions in the global namespace. In this
case Angular provides a service, `$controller`, which will retrieve your controller by name. Here
is the same test using `$controller`:
In practice, you will not want to have your controller functions in the global namespace. Instead,
we have registered our controllers in the `phonecatApp` module. In this case Angular provides a
service, `$controller`, which will retrieve your controller by name. Here is the same test using
`$controller`:
__`test/unit/controllersSpec.js`:__
<pre>
describe('PhoneCat controllers', function() {
beforeEach(module('phonecatApp'));
describe('PhoneListCtrl', function(){
@ -171,6 +173,9 @@ describe('PhoneCat controllers', function() {
});
</pre>
Don't forget that we need to load up the `phonecatApp` module into the test so that the controller
is available to be injected.
### Writing and Running Tests
Angular developers prefer the syntax of Jasmine's Behavior-driven Development (BDD) framework when
writing tests. Although Angular does not require you to use Jasmine, we wrote all of the tests in