mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
test($compile): add test for optional require in directives with ^ operator
The directive property `require` allows optional requirement via the `?` before or after the `^` operator. Add tests to ensure this functionality is not lost inadvertently. Closes #9391 Closes #9392
This commit is contained in:
committed by
Caitlin Potter
parent
d0226ebbbf
commit
4bf254c155
@@ -4197,6 +4197,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() {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user