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

fix($compile): use correct parent element when requiring on html element #16647

Merged
merged 1 commit into from
Jul 27, 2018

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Jul 26, 2018

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change?

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

You might be able to unit-test this by mocking .parent() to return {nodeType: NODE_TYPE_DOCUMENT} or something, but it would already be messy enough.
I think it's fine to only have the e2e test.

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html ng-app="test" require-directive parent-directive>
Copy link
Member

Choose a reason for hiding this comment

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

parentDirective isn't a parent directive. I would name it siblingDirective or notParentDirective to make it obvious.
(I was kind of confused at first.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it's supposed to be the parent Directive. The require directive requires it on one of its parent elements but also has it itself for the sake of the test.

Copy link
Member

Choose a reason for hiding this comment

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

No, it's a bug in requireDirective 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the user uses it incorrectrly! :D

@Narretz Narretz force-pushed the fix-ng-model-options-html branch from 396071a to dd00eaf Compare July 27, 2018 08:02
@Narretz
Copy link
Contributor Author

Narretz commented Jul 27, 2018

This is taking longer than anticipated. Turns out you cannot access the FF logs on Selenium. I changed it to check for a DOM element instead of the error message.

@Narretz Narretz force-pushed the fix-ng-model-options-html branch from 6eb77e8 to 874cd3d Compare July 27, 2018 11:45
return {
require: '^^requireTargetDirective',
link: function(scope, element, attrs, ctrl) {
window.document.querySelector('#container').append(window.document.createTextNode(ctrl.content));
Copy link
Member

Choose a reason for hiding this comment

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

You can also do: .textContent = ctrl.content 😁

'use strict';

angular.
module('test', []).
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better if you overwrote $exceptionHandler to put the error message into a DOM element.
Then you could easily read the error in the test (and verify that it is what you expect).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, didn't think of that

@Narretz Narretz force-pushed the fix-ng-model-options-html branch from 0256df7 to 0059b66 Compare July 27, 2018 15:09
@Narretz Narretz merged commit aa7d45e into angular:master Jul 27, 2018
@Narretz Narretz deleted the fix-ng-model-options-html branch July 27, 2018 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants