Skip to content

feat(debug): replace DebugElement with new Debug DOM#6555

Closed
juliemr wants to merge 1 commit intoangular:masterfrom
juliemr:debug-dom-18012016
Closed

feat(debug): replace DebugElement with new Debug DOM#6555
juliemr wants to merge 1 commit intoangular:masterfrom
juliemr:debug-dom-18012016

Conversation

@juliemr
Copy link
Copy Markdown
Member

@juliemr juliemr commented Jan 19, 2016

Now, using ng.probe(element) in the browser console returns
a DebugElement when in dev mode.

ComponentFixture#debugElement also returns a new DebugElement.

Breaking Change:

This is a breaking change for unit tests. The API for the DebugElement
has changed. Now, there is a DebugElement or DebugNode for every node
in the DOM, not only nodes with an ElementRef. componentViewChildren is
removed, and childNodes is a list of ElementNodes corresponding to every
child in the DOM. query no longer takes a scope parameter, since
the entire rendered DOM is included in the childNodes.

Before:

componentFixture.debugElement.componentViewChildren[0];

After

// Depending on the DOM structure of your component, the
// index may have changed or the first component child
// may be a sub-child.
componentFixture.debugElement.children[0];

Before:

debugElement.query(By.css('div'), Scope.all());

After:

debugElement.query(By.css('div'));

Before:

componentFixture.debugElement.elementRef;

After:

componentFixture.elementRef;

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 19, 2016

@tbosch this is a work in progress, as some tests are not yet upgraded. However, the API changes are complete and the unit tests for the new DebugElement are done, and it would be great to get feedback. Particularly, I'm not thrilled with the API for Renderer#setInjectableMirrors, which is kind of a grab bag for all sorts of info we need from the view.

cc @jelbourn @wardbell , this is a heads up of some breaking changes to the unit test API. Feedback appreciated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This name is deeply mysterious. No doc comments. What does it do?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It adds info from the AppElement and AppView (injectable tokens, the injector itself, and the current component) that we'll need for debugging.

It's a renderer function, so it should be internal and a user should never have to bother with it. In any case, it's probably a good idea to add a comment, I'll do that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comment at the implementation

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 19, 2016

Remaining tasks

  • Fix tests that are failing due to the breaking changes
  • Create before/after examples for the breaking changes in the commit message

@juliemr juliemr added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jan 19, 2016
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 22, 2016

I've added a commit which fixes Angular's tests, adds a couple necessary features to DebugElement, and removes the ViewListener. Please take a look!

@juliemr juliemr force-pushed the debug-dom-18012016 branch from 0d3d3d4 to 66251bc Compare January 22, 2016 08:31
@juliemr juliemr force-pushed the debug-dom-18012016 branch 2 times, most recently from 2e8a600 to 4b150f9 Compare January 22, 2016 08:41
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 22, 2016

I've created a doc to track the changes that will be necessary for the merge to g3: https://docs.google.com/document/d/1wdODXGw8k_bCCYvPzxFxRX7jfAxHn7SXwTCpfsCL07c/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to be a directiveTypes: Type[]?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better: providerTokens: any[]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

@tbosch tbosch added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 22, 2016
@tbosch
Copy link
Copy Markdown
Contributor

tbosch commented Jan 22, 2016

@juliemr this looks already pretty good. Left some comments...

@tbosch
Copy link
Copy Markdown
Contributor

tbosch commented Jan 22, 2016

Btw, don't worry about the circle CI failure, @IgorMinar said we can ignore it for now...

@juliemr juliemr force-pushed the debug-dom-18012016 branch from 4b150f9 to 36419f0 Compare January 24, 2016 06:52
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 24, 2016

Thanks for the review - all done except for platform location question above.

I squashed the commits and added before/after examples to the breaking changes in the commit message.

@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 27, 2016

Dear merge-master - this is not quite ready for merge yet. There are some pending g3 issues that I am working on addressing - the doc has been updated.

@juliemr juliemr removed the action: merge The PR is ready for merge by the caretaker label Jan 27, 2016
@juliemr juliemr force-pushed the debug-dom-18012016 branch 2 times, most recently from 8a55baf to 8d57a18 Compare January 27, 2016 20:21
@juliemr juliemr added the action: merge The PR is ready for merge by the caretaker label Jan 28, 2016
@juliemr
Copy link
Copy Markdown
Member Author

juliemr commented Jan 28, 2016

Now ready for merge! I have prepared fixes for all g3 issues, they are linked in the doc.

@juliemr juliemr assigned alexeagle and unassigned tbosch Jan 28, 2016
@alexeagle
Copy link
Copy Markdown
Contributor

Missing LGTM - @tbosch ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this todo

@tbosch tbosch added pr_state: LGTM action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jan 28, 2016
@juliemr juliemr force-pushed the debug-dom-18012016 branch from 8d57a18 to f668ab2 Compare January 28, 2016 17:55
@juliemr juliemr removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 28, 2016
Now, using `ng.probe(element)` in the browser console returns
a DebugElement when in dev mode.

`ComponentFixture#debugElement` also returns a new DebugElement.

Breaking Change:

This is a breaking change for unit tests. The API for the DebugElement
has changed. Now, there is a DebugElement or DebugNode for every node
in the DOM, not only nodes with an ElementRef. `componentViewChildren` is
removed, and `childNodes` is a list of ElementNodes corresponding to every
child in the DOM. `query` no longer takes a scope parameter, since
the entire rendered DOM is included in the `childNodes`.

Before:

```
componentFixture.debugElement.componentViewChildren[0];
```

After
```
// Depending on the DOM structure of your component, the
// index may have changed or the first component child
// may be a sub-child.
componentFixture.debugElement.children[0];
```

Before:

```
debugElement.query(By.css('div'), Scope.all());
```

After:

```
debugElement.query(By.css('div'));
```

Before:

```
componentFixture.debugElement.elementRef;
```

After:

```
componentFixture.elementRef;
```
@alexeagle
Copy link
Copy Markdown
Contributor

merged as e1bf3d3

@alexeagle alexeagle closed this Jan 29, 2016
juliemr added a commit to juliemr/angular that referenced this pull request Jan 29, 2016
@siddharthjain210
Copy link
Copy Markdown

siddharthjain210 commented Apr 24, 2016

I have created a sample application with angular2.beta13. Also i have used the test framework by taking guidelines from angular2-seed project by mgechev.
When i am debugging my unit test cases in phantomjs, instead of DebugRenderer, DOMRenderer is instanciated, because of which my test cases with TestComponentBuilder are failing. Please let me know what else i need to do.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker breaking changes cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants