-
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
test($compile): add test for optional require
in directives with ^
operator
#9392
Conversation
…` 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
And here are more tests for |
}); | ||
|
||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
don't say "should not throw", say "should inject null
" instead, I guess basically the controller should be null, not any other value
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.
Looks like it's injecting "undefined" instead (or rather, not passing that arg at all). How about:
"should not pass a controller if required controller can't be found and is optional with the question mark on the right"
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.
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 comment
The 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:
"should pass null if required controller can't be found and is optional with the question mark on the right"
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no --- I would just change the return value;
to return value || null;
--- much easier
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.
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.
Currently, `undefined` is returned. However, the desired behavior is to return `null` when the controller is optional and not found. Closes #9404
There's the fix @caitp, thanks! |
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
The directive property
require
allows optional requirement viathe
?
before or after the^
operator. Add tests to ensure thisfunctionality is not lost inadvertently.
Closes #9391