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

test($compile): add test for optional require in directives with ^ operator #9392

Closed
wants to merge 2 commits into from
Closed

test($compile): add test for optional require in directives with ^ operator #9392

wants to merge 2 commits into from

Conversation

kentcdodds
Copy link
Member

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

…` 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
@kentcdodds
Copy link
Member Author

And here are more tests for require: '?^main' and require: '^?main' @caitp. Thanks!

});


it("should not throw an error if required controller can't be found and is optional with the question mark on the right",function() {
Copy link
Contributor

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

Copy link
Member Author

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"

Copy link
Contributor

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

Copy link
Member Author

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!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caitp, I'm planning on adding || null to this line which fixes this bug.

                                            //  all tests pass when I add this ↓
value = value || $searchElement[retrievalMethod]('$' + require + 'Controller') || null;

Preparing a PR now. Let me know if you think that there's a better solution.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member Author

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
@kentcdodds
Copy link
Member Author

There's the fix @caitp, thanks!

@btford btford added this to the Backlog milestone Oct 7, 2014
@jeffbcross jeffbcross force-pushed the master branch 4 times, most recently from e8dc429 to e83fab9 Compare October 10, 2014 17:38
@caitp caitp closed this in 4bf254c Oct 24, 2014
caitp pushed a commit that referenced this pull request Oct 24, 2014
Currently, `undefined` is returned. However, the desired behavior is to
return `null` when the controller is optional and not found.

(If this breaks your app, it really shouldn't .v.)

Closes #9404
Closes #9392
@kentcdodds kentcdodds deleted the add-test-for-optional-required-controller branch October 24, 2014 19:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test for optional required controllers
4 participants