question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

This library calls detect changes on every property change

See original GitHub issue
@Component({
  template: `
    count: {{ count }}
    <button (click)="increment()">Increment</button>
  `
})
export class Counter {
  elementRef = inject(ElementRef)
  count = 0

  increment() {
    this.count++
    this.count++
    this.count++

    expect(elementRef.nativeElement).toHaveTextContent("count: 0")
  }
}
await render(Counter)

fireEvent.click(screen.getByText("Increment"))

Expected result: count: 0 Actual result: count: 3

This is not correct Angular behavior and breaks custom change detection strategies.

Proposal: Use ComponentRef#setInput to change component properties instead.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
timdeschryvercommented, Dec 14, 2022

This is released in v13 🥳 Thanks @antischematic !

1reaction
antischematiccommented, Dec 10, 2022

@timdeschryver Thanks for that, my tests are now passing 13.0.0-beta-9 without any issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Change Detection - How Does It Really Work?
Angular can detect when component data changes, and then automatically re-render the view to reflect that change. But how can it do so...
Read more >
ChangeDetectorRef - Angular
ChangeDetectorReflink. Base class that provides change detection functionality. A change-detection tree collects all views that are to be checked for changes.
Read more >
Simplified Angular Change Detection | by Pankaj Parkar | ngconf
It runs a change detection for a component only when Input bindings value of a component is changed. Actually, it compares the reference...
Read more >
The Last Guide For Angular Change Detection You'll Ever Need
This detector compares the current value with the previous value of the property. If the value has changed it will set isChanged to...
Read more >
Listener for property value changes in a Javascript object
It also has a simple type check, which calls the onerror event if it fails. ... Whenever the p property is changed, any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found