File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1087,10 +1087,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1087
1087
* @returns {ng.$compileProvider } Self for chaining.
1088
1088
*/
1089
1089
this . directive = function registerDirective ( name , directiveFactory ) {
1090
+ assertArg ( name , 'name' ) ;
1090
1091
assertNotHasOwnProperty ( name , 'directive' ) ;
1091
1092
if ( isString ( name ) ) {
1092
1093
assertValidDirectiveName ( name ) ;
1093
- assertArg ( directiveFactory , 'directiveFactory' ) ;
1094
+ assertArgFn ( directiveFactory , 'directiveFactory' , true ) ;
1094
1095
if ( ! hasDirectives . hasOwnProperty ( name ) ) {
1095
1096
hasDirectives [ name ] = [ ] ;
1096
1097
$provide . factory ( name + Suffix , [ '$injector' , '$exceptionHandler' ,
Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ describe('$compile', function() {
214
214
} ) ;
215
215
inject ( function ( $compile ) { } ) ;
216
216
} ) ;
217
+
217
218
it ( 'should throw an exception if a directive name has leading or trailing whitespace' , function ( ) {
218
219
module ( function ( ) {
219
220
function assertLeadingOrTrailingWhitespaceInDirectiveName ( name ) {
@@ -230,6 +231,33 @@ describe('$compile', function() {
230
231
inject ( function ( $compile ) { } ) ;
231
232
} ) ;
232
233
234
+ it ( 'should throw an exception if the directive name is not defined' , function ( ) {
235
+ module ( function ( ) {
236
+ expect ( function ( ) {
237
+ directive ( ) ;
238
+ } ) . toThrowMinErr ( 'ng' , 'areq' ) ;
239
+ } ) ;
240
+ inject ( function ( $compile ) { } ) ;
241
+ } ) ;
242
+
243
+ it ( 'should throw an exception if the directive factory is not a function' , function ( ) {
244
+ module ( function ( ) {
245
+ expect ( function ( ) {
246
+ directive ( 'myDir' ) ;
247
+ } ) . toThrowMinErr ( 'ng' , 'areq' ) ;
248
+ } ) ;
249
+ inject ( function ( $compile ) { } ) ;
250
+ } ) ;
251
+
252
+ it ( 'should accept array notation in the directive factory function' , function ( ) {
253
+ module ( function ( ) {
254
+ directive ( 'myDir' , [ 'log' , function ( log ) {
255
+ expect ( log ) . toBe ( jasmine . any ( 'Function' ) ) ;
256
+ } ] ) ;
257
+ } ) ;
258
+ inject ( function ( $compile ) { } ) ;
259
+ } ) ;
260
+
233
261
it ( 'should preserve context within declaration' , function ( ) {
234
262
module ( function ( ) {
235
263
directive ( 'ff' , function ( log ) {
You can’t perform that action at this time.
0 commit comments