-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(unit testing): improve unit testing guide #10183
docs(unit testing): improve unit testing guide #10183
Conversation
CLAs look good, thanks! |
3d8aca7
to
e28012c
Compare
```js | ||
angular | ||
.module('app') | ||
.controller('PasswordCtrl', function PasswordCtrl($scope) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rename this to PasswordController
please? We are trying to get rid of the Ctrl
suffix because it causes ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also use the DI annotations:
.controller('PasswordController', ['$scope', function PasswordCtrl($scope) { ...
we no longer support controllers in the global scope, so we should not use that in examples. @btford can you also take a look please? |
e28012c
to
474a629
Compare
@IgorMinar so the dependency injection stuff kind of exists here: https://code.angularjs.org/snapshot/docs/guide/di If we wanted to move the bit about DI that's in this guide, then the above link is probably the best place to put it. |
Cool, that's what I thought. I will update the examples :) |
below: | ||
## Additional libraries for testing Angular applications | ||
|
||
For testing Angular applications there are libraries that you should use that will make testing much |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "tools" instead of "libraries." Karma isn't really a "library"
474a629
to
393e4ce
Compare
}); | ||
``` | ||
|
||
The duplication is now gone, and encapsulated within the `beforeEach`. Each individual test now only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplication is now gone, and encapsulated within the
beforeEach
This reads weirdly to me. Consider something like "We moved duplicate behavior into the beforeEach
block" instead.
@jackfranklin – when you're done could you squash these commits? Thanks! |
e7a4a1e
to
0ce7034
Compare
@btford how do you feel about moving the section on DI (https://github.com/jackfranklin/angular.js/blob/unit-testing-docs-improving/docs/content/guide/unit-testing.ngdoc#L38) out, and maybe putting it onto this page? https://code.angularjs.org/snapshot/docs/guide/di It doesn't really make sense to exist here, better to just link off to the DI guide. Edit: in fact, most of the content on DI that exists in this guide already exists in the DI guide, so maybe it's just a case of getting rid of it? |
@jackfranklin – totally agree. Move that section to the DI docs, and if you can find a place in the testing docs, link to the moved section. |
If the info is duplicated you can just drop it. |
@btford can you take a look at the last commit? Once it's done I'll squash :) |
Looks good. Squash away! |
This commit adds to the unit testing guide: - add explicit section on additional libraries: Karma, Jasmine and angular-mocks and link to the docs for those projects too. Explain the benefit and use case for each of these libaries - Add more fully featured test examples and add more documentation around them, in particular the controller test - more clearly distinguish between the section on principles of testing and actual tutorial on writing a test This should close angular#8220.
0aa560e
to
89179db
Compare
Woo! Squished :) |
Landed as 3109342. Thanks for the awesome work! |
This commit adds to the unit testing guide:
angular-mocks and link to the docs for those projects too. Explain the
benefit and use case for each of these libaries
around them, in particular the controller test
and actual tutorial on writing a test
This should close #8220.
Questions
One thing that I wasn't sure on was if to update the controller tests to not presume the controller is in the global scope. In the original issue (#8220) it says:
So I left the controllers as is, but it feels beneficial to me to update the controller example. Is there any reason why that can't be done now? That issue mentioned (#5076) is more about the
controllerAs
syntax, but the main problem with the test example right now is that the controllers are global.Secondly, the entire discussion about the different ways of dependency injection - most people will be familiar with how Angular does this and hence talking about other mechanisms doesn't seem that worthwhile?