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

docs(guide/component): fix for component controller unit-test example #14443

Closed
wants to merge 1 commit into from
Closed

docs(guide/component): fix for component controller unit-test example #14443

wants to merge 1 commit into from

Conversation

mjwwit
Copy link
Contributor

@mjwwit mjwwit commented Apr 15, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Docs update.

What is the current behavior? (You can also link to an open issue here)
Error in docs is described in #14426.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

@@ -233,9 +233,13 @@ it upwards to the heroList component, which updates the original data.
</file>

<file name="heroDetail.js">
function HeroDetailController($scope, $element, $attrs) {
function HeroDetailController($scope) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need $scope here ? Did you leave it on purpose ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the absolute minimum number of changes to make the unit tests pass. In the unit tests the $componentController is provided with a $scope value, but not with $element or $attrs.
The $scope service is not being used in the controller though, so it might as well be removed.

If I'm not wrong, a PR was merged the other day removing the requirement to always provide $scope in $componentController locals, so it can be removed from there as well.
I can update the PR if you like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Please, do remove the unnecessary $scope and update the test to not provide one.

@mjwwit
Copy link
Contributor Author

mjwwit commented Apr 21, 2016

I've removed the $scope references, and removed an outdated comment.

Isn't there some way you can get the unit tests to automatically run from docs using dgeni? It's already parsing the code snippets and putting them into files. Maybe it's possible to generate a karma config and run tests as well.

@gkalpak
Copy link
Member

gkalpak commented Apr 22, 2016

We are running the e2e tests from the docs. Not sure if we are already doing the same for the guide.
Being able to run unit tests would be nice, but it won't be trivial I guess.

@@ -464,8 +468,7 @@ describe('component: heroDetail', function() {
}));

it('should set the default values of the hero', function() {
// It's necessary to always pass the scope in the locals, so that the controller instance can be bound to it
component = $componentController('heroDetail', {$scope: scope});
component = $componentController('heroDetail', {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I prefer to omit the unnecessary locals argument altogether (or pass null where we want a 3rd argument).

@gkalpak
Copy link
Member

gkalpak commented Apr 25, 2016

Except for the fact that I am not a big fan of the initialization logic (see https://github.com/angular/angular.js/pull/14443/files#r60963112), it LGTM.
Feel free to also remove unnecessarily injected arguments to other controllers.

@gkalpak gkalpak closed this in b9d76bf Apr 26, 2016
gkalpak pushed a commit that referenced this pull request Apr 26, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants