perform detectChanges internally upon spectator.query call #552
Replies: 4 comments 3 replies
-
It doesn't make sense to call |
Beta Was this translation helpful? Give feedback.
-
It makes sense to me to call it right before the query. Why does it not makes sense to you? |
Beta Was this translation helpful? Give feedback.
-
I think it's common in the test to mock observables (such as HTTP requests) with Subjects. In contrast to the actual HTTP request, zones will not pick up the emission from the subject, so detectChanges won't be called. That's why the developer has to do it manually in the test, which is annoying. This seems like an excellent opportunity to automate. In addition, Angular states that "there is no harm in calling detectChanges() more often than is strictly necessary." |
Beta Was this translation helpful? Give feedback.
-
following your logic when you said: "Changing the component inputs will check the component"... |
Beta Was this translation helpful? Give feedback.
-
I often write components using OnPush ChangeDetection (pretty much exclusively). In addition, often I write code based on rxjs streams. With that in mind, I often stub observables in my unit tests. So recently I wondered, why I have to manually call
detectChanges
in my tests in these situations.I was wrongly under impression that
async
pipe would calldetectChanges
for me. However, that's not the case. Under the hood, it callsmarkForCheck
.So what if we added a call to
detectChanges
inside thespectator.query(...)
call? I would think that if I'm quering for an element, I want my DOM to be in sync with the state at that time. Spectator already does something similar withsetInnput
call.Beta Was this translation helpful? Give feedback.
All reactions