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

test($rootScope): add $watch/$watchCollection tests #15949

Merged
merged 3 commits into from
May 10, 2017

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Apr 29, 2017

These are various cases that I felt were missing tests, mainly around constant/literal/one-time $watch/$watchCollection.

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.

Awesome (except for the indentation issues 😛)
💯

@@ -212,10 +212,52 @@ describe('Scope', function() {
expect($rootScope.$$watchersCount).toBe(2);
}));

it('should not keep constant literals on the watch queue', inject(function($rootScope) {
it('should remove $watch of constant literals after initial digest', inject(function($rootScope) {
Copy link
Member

Choose a reason for hiding this comment

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

Wrong indentation (here and below).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand, isn't it the same as before and the same as all the others around it?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, it turned out I had a Chrome extension that was messing the GitHub diffs. 😞
Indentation is fine.

Copy link
Contributor

@Narretz Narretz left a comment

Choose a reason for hiding this comment

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

Tests look good (based on my limited understanding :D) but I would like the specs to be put into the relevant describes.

expect($rootScope.$$watchers.length).toEqual(0);
}));

it('should remove $watchCollection of constant literals after initial digest', inject(function($rootScope) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a $watchCollection describe in this file, I think the watchCollection specs should go there (also for all the other watchCollection tests you've added)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That describe block has a beforeEach that does $watchCollection("var", ...) so I converted it to describe("$watchCollection var", ...).

Maybe I should add a parent describe("$watchCollection", ...) that wraps the var/literal/constant describes and can also contain this test?

I'll do that now...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually this specific $watchCollection test is beside the equivalent $watch test.

What's better, putting similar watch/watchCollection beside each other or separating them into watch/watchCollection groups? I feel like this specific test is better grouped along with other constant related tests instead of with $watchCollection...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, how about wrapping the constant related watch and watchCollection tests with another describe? Btw, what about watchGroup :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've wrapped the constant-cleanup and onetime-cleanup tests into describe blocks. Also added some watchGroup tests.

@jbedard
Copy link
Collaborator Author

jbedard commented May 5, 2017

I've wrapped all the describe('$watchCollection X' blocks into one parent describe('$watchCollection', and removed a couple unnecessary vars/inject-params. See the second commit. I think the commits should be squashed before merging though.

@Narretz can you clarify your comment? I'd like to get this merged so I can add more... 😃

Copy link
Contributor

@Narretz Narretz left a comment

Choose a reason for hiding this comment

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

Thanks @jbedard!

@Narretz
Copy link
Contributor

Narretz commented May 9, 2017

There are some lint errors, otherwise LGTM

@jbedard
Copy link
Collaborator Author

jbedard commented May 9, 2017

Fixed the lint issues. I'll squash and merge later today if no one else gets to it.

@jbedard jbedard merged commit d0d8298 into angular:master May 10, 2017
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.

4 participants