Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4bf254c

Browse files
Kent C. Doddscaitp
Kent C. Dodds
authored andcommitted
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
1 parent d0226eb commit 4bf254c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/ng/compileSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -4197,6 +4197,42 @@ describe('$compile', function() {
41974197
});
41984198

41994199

4200+
it("should not throw an error if required controller can't be found and is optional",function() {
4201+
module(function() {
4202+
directive('dep', function(log) {
4203+
return {
4204+
require: '?^main',
4205+
link: function(scope, element, attrs, controller) {
4206+
log('dep:' + !!controller);
4207+
}
4208+
};
4209+
});
4210+
});
4211+
inject(function(log, $compile, $rootScope) {
4212+
$compile('<div main><div dep></div></div>')($rootScope);
4213+
expect(log).toEqual('dep:false');
4214+
});
4215+
});
4216+
4217+
4218+
it("should not throw an error if required controller can't be found and is optional with the question mark on the right",function() {
4219+
module(function() {
4220+
directive('dep', function(log) {
4221+
return {
4222+
require: '^?main',
4223+
link: function(scope, element, attrs, controller) {
4224+
log('dep:' + !!controller);
4225+
}
4226+
};
4227+
});
4228+
});
4229+
inject(function(log, $compile, $rootScope) {
4230+
$compile('<div main><div dep></div></div>')($rootScope);
4231+
expect(log).toEqual('dep:false');
4232+
});
4233+
});
4234+
4235+
42004236
it('should have optional controller on current element', function() {
42014237
module(function() {
42024238
directive('dep', function(log) {

0 commit comments

Comments
 (0)