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:
Kent C. Dodds
2014-10-02 10:30:23 -06:00
committed by Caitlin Potter
parent d0226ebbbf
commit 4bf254c155

View File

@@ -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) {