-
Notifications
You must be signed in to change notification settings - Fork 27.4k
test($compile): add test for optional require
in directives with ^
operator
#9392
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4095,6 +4095,42 @@ describe('$compile', function() { | |
}); | ||
|
||
|
||
it("should not throw an error if required controller can't be found and is optional",function() { | ||
module(function() { | ||
directive('dep', function(log) { | ||
return { | ||
require: '?^main', | ||
link: function(scope, element, attrs, controller) { | ||
log('dep:' + !!controller); | ||
} | ||
}; | ||
}); | ||
}); | ||
inject(function(log, $compile, $rootScope) { | ||
$compile('<div main><div dep></div></div>')($rootScope); | ||
expect(log).toEqual('dep:false'); | ||
}); | ||
}); | ||
|
||
|
||
it("should not throw an error if required controller can't be found and is optional with the question mark on the right",function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't say "should not throw", say "should inject There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's injecting "undefined" instead (or rather, not passing that arg at all). How about: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually supposed to pass null --- but I see that it doesn't if the controller isn't found and it's optional. That's a bug, you should fix it in this PR tbh, it will let us write better tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so the actual behavior should be that it passes null if it's not found and optional. So it should say: I'll try to find time to fix the bug as part of this PR. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's perfect, should be fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually no --- I would just change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I went with initially, but then saw this line and thought it might make more sense to keep the value assignment in one place. But I personally like adding it to the return statement instead. I'll go with that. |
||
module(function() { | ||
directive('dep', function(log) { | ||
return { | ||
require: '^?main', | ||
link: function(scope, element, attrs, controller) { | ||
log('dep:' + !!controller); | ||
} | ||
}; | ||
}); | ||
}); | ||
inject(function(log, $compile, $rootScope) { | ||
$compile('<div main><div dep></div></div>')($rootScope); | ||
expect(log).toEqual('dep:false'); | ||
}); | ||
}); | ||
|
||
|
||
it('should have optional controller on current element', function() { | ||
module(function() { | ||
directive('dep', function(log) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here