Skip to content

Commit 2c9c3a0

Browse files
lisapfistererNarretz
authored andcommitted
docs(guide/Unit Testing): change $scope = {} to $scope = $rootScope.$new()
{} will just create an empty object. This will break if the module uses for example $watch or others. While it's not necessary for this example, it's good general practice. Closes angular#16315
1 parent 817ac56 commit 2c9c3a0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/content/guide/unit-testing.ngdoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,17 @@ for instantiating controllers.
149149
describe('PasswordController', function() {
150150
beforeEach(module('app'));
151151

152-
var $controller;
152+
var $controller, $rootScope;
153153

154-
beforeEach(inject(function(_$controller_){
154+
beforeEach(inject(function(_$controller_, _$rootScope_){
155155
// The injector unwraps the underscores (_) from around the parameter names when matching
156156
$controller = _$controller_;
157+
$rootScope = _$rootScope_;
157158
}));
158159

159160
describe('$scope.grade', function() {
160161
it('sets the strength to "strong" if the password length is >8 chars', function() {
161-
var $scope = {};
162+
var $scope = $rootScope.$new();
162163
var controller = $controller('PasswordController', { $scope: $scope });
163164
$scope.password = 'longerthaneightchars';
164165
$scope.grade();

0 commit comments

Comments
 (0)