Skip to content

Commit 11fa1a8

Browse files
committed
pattern(directive): add require ngModel pattern
1 parent f1fce94 commit 11fa1a8

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

example/coffeescript/app.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ angular.module('myApp')
7676
.directive 'myDir', [ ->
7777
template: '<div></div>'
7878
restrict: 'EAC'
79+
require: 'ngModel'
7980
link: (scope, element, attrs) ->
8081
element.text 'this is my directive'
8182
]

example/javascript/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ angular.module('myApp')
8181
return {
8282
template: '<div></div>',
8383
restrict: 'EAC',
84+
require: 'ngModel',
8485
link: function (scope, element, attrs) {
8586
return element.text('this is my directive');
8687
}

patterns/directive.md

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* [Suggested Setup](#suggested-directive-unit-test-setup-)
66
* When created
7+
* [should throw error when ngModel attribute not defined](#throw-error-when-ngmodel-attribute-not-defined-)
78
* [should render the expected output](#render-the-expected-output-)
89
* When the model changes
910
* *[pull request welcome!](../#contributing-test-patterns)*
@@ -120,6 +121,25 @@ describe('Directive: myDir', function () {
120121

121122
#### My directive should:
122123

124+
#####throw error when ngModel attribute not defined [&#8593;](#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+
123143
#####render the expected output [&#8593;](#testing-patterns)
124144
```CoffeeScript
125145
# CoffeeScript

0 commit comments

Comments
 (0)