Skip to content
This repository was archived by the owner on Mar 26, 2018. It is now read-only.

Commit 2753c99

Browse files
passybtford
authored andcommitted
fix(templates): new scope for directive spec
To mirror the controller spec template, the generated tests for directives now mock a new scope instead of working directly on the $rootScope.
1 parent cd46aa8 commit 2753c99

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict'
22

33
describe 'Directive: <%= _.camelize(name) %>', () ->
4+
5+
# load the directive's module
46
beforeEach module '<%= _.camelize(appname) %>App'
57

6-
element = {}
8+
scope = {}
9+
10+
beforeEach inject ($controller, $rootScope) ->
11+
scope = $rootScope.$new()
712

8-
it 'should make hidden element visible', inject ($rootScope, $compile) ->
13+
it 'should make hidden element visible', inject ($compile) ->
914
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
10-
element = $compile(element) $rootScope
15+
element = $compile(element) scope
1116
expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive'
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict'
22

33
describe 'Directive: <%= _.camelize(name) %>', () ->
4+
5+
# load the directive's module
46
beforeEach module '<%= _.camelize(appname) %>App'
57

6-
element = {}
8+
scope = {}
9+
10+
beforeEach inject ($controller, $rootScope) ->
11+
scope = $rootScope.$new()
712

8-
it 'should make hidden element visible', inject ($rootScope, $compile) ->
13+
it 'should make hidden element visible', inject ($compile) ->
914
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
10-
element = $compile(element) $rootScope
15+
element = $compile(element) scope
1116
expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive'
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
'use strict';
22

33
describe('Directive: <%= _.camelize(name) %>', function () {
4+
5+
// load the directive's module
46
beforeEach(module('<%= _.camelize(appname) %>App'));
57

6-
var element;
8+
var element,
9+
scope;
10+
11+
beforeEach(inject(function ($rootScope) {
12+
scope = $rootScope.$new();
13+
}));
714

8-
it('should make hidden element visible', inject(function ($rootScope, $compile) {
15+
it('should make hidden element visible', inject(function ($compile) {
916
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>');
10-
element = $compile(element)($rootScope);
17+
element = $compile(element)(scope);
1118
expect(element.text()).toBe('this is the <%= _.camelize(name) %> directive');
1219
}));
1320
});
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
'use strict';
22

33
describe('Directive: <%= _.camelize(name) %>', function () {
4+
5+
// load the directive's module
46
beforeEach(module('<%= _.camelize(appname) %>App'));
57

6-
var element;
8+
var element,
9+
scope;
10+
11+
beforeEach(inject(function ($rootScope) {
12+
scope = $rootScope.$new();
13+
}));
714

8-
it('should make hidden element visible', inject(function ($rootScope, $compile) {
15+
it('should make hidden element visible', inject(function ($compile) {
916
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>');
10-
element = $compile(element)($rootScope);
17+
element = $compile(element)(scope);
1118
expect(element.text()).toBe('this is the <%= _.camelize(name) %> directive');
1219
}));
1320
});

0 commit comments

Comments
 (0)