Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c1e6afc

Browse files
DanSpetebacondarwin
authored andcommitted
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
1 parent 280354c commit c1e6afc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/content/tutorial/step_02.ngdoc

+8-3
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ Angular. Since testing is such a critical part of software development, we make
151151
tests in Angular so that developers are encouraged to write them.
152152

153153
### Testing non-Global Controllers
154-
In practice, you will not want to have your controller functions in the global namespace. In this
155-
case Angular provides a service, `$controller`, which will retrieve your controller by name. Here
156-
is the same test using `$controller`:
154+
In practice, you will not want to have your controller functions in the global namespace. Instead,
155+
we have registered our controllers in the `phonecatApp` module. In this case Angular provides a
156+
service, `$controller`, which will retrieve your controller by name. Here is the same test using
157+
`$controller`:
157158

158159
__`test/unit/controllersSpec.js`:__
159160
<pre>
160161
describe('PhoneCat controllers', function() {
162+
beforeEach(module('phonecatApp'));
161163

162164
describe('PhoneListCtrl', function(){
163165

@@ -171,6 +173,9 @@ describe('PhoneCat controllers', function() {
171173
});
172174
</pre>
173175

176+
Don't forget that we need to load up the `phonecatApp` module into the test so that the controller
177+
is available to be injected.
178+
174179
### Writing and Running Tests
175180
Angular developers prefer the syntax of Jasmine's Behavior-driven Development (BDD) framework when
176181
writing tests. Although Angular does not require you to use Jasmine, we wrote all of the tests in

0 commit comments

Comments
 (0)