File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ angular.module('myApp')
76
76
.directive ' myDir' , [ ->
77
77
template : ' <div></div>'
78
78
restrict : ' EAC'
79
+ require : ' ngModel'
79
80
link : (scope , element , attrs ) ->
80
81
element .text ' this is my directive'
81
82
]
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ angular.module('myApp')
81
81
return {
82
82
template : '<div></div>' ,
83
83
restrict : 'EAC' ,
84
+ require : 'ngModel' ,
84
85
link : function ( scope , element , attrs ) {
85
86
return element . text ( 'this is my directive' ) ;
86
87
}
Original file line number Diff line number Diff line change 4
4
5
5
* [ Suggested Setup] ( #suggested-directive-unit-test-setup- )
6
6
* When created
7
+ * [ should throw error when ngModel attribute not defined] ( #throw-error-when-ngmodel-attribute-not-defined- )
7
8
* [ should render the expected output] ( #render-the-expected-output- )
8
9
* When the model changes
9
10
* * [ pull request welcome!] ( ../#contributing-test-patterns ) *
@@ -120,6 +121,25 @@ describe('Directive: myDir', function () {
120
121
121
122
#### My directive should:
122
123
124
+ #####throw error when ngModel attribute not defined [ ↑ ; ] ( #testing-patterns )
125
+ ``` CoffeeScript
126
+ # CoffeeScript
127
+ it ' should throw error when ngModel attribute not defined' , ->
128
+ invalidTemplate = ->
129
+ createDirective null , ' <my-dir></my-dir>'
130
+ expect (invalidTemplate).toThrow new Error (' No controller: ngModel' )
131
+ ```
132
+
133
+ ``` JavaScript
134
+ // JavaScript
135
+ it (' should throw error when ngModel attribute not defined' , function () {
136
+ function invalidTemplate () {
137
+ createDirective (null , ' <my-dir></my-dir>' );
138
+ }
139
+ expect (invalidTemplate).toThrow (new Error (' No controller: ngModel' ));
140
+ });
141
+ ```
142
+
123
143
#####render the expected output [ ↑ ; ] ( #testing-patterns )
124
144
``` CoffeeScript
125
145
# CoffeeScript
You can’t perform that action at this time.
0 commit comments