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.

Change input after initial render

See original GitHub issue

Hi!

What’s the correct way to change input after initial render ? Because componentProperties only set input on the first render, but we cannot test subsequent input changes this way (which leads to subsequent calls to ngOnChanges).

For now, this works :

component.fixture.componentInstance.myInput = 'stuff';
component.detectChanges();

But accessing fixture is not recommended (https://testing-library.com/docs/angular-testing-library/api#fixture, and I agree with this), and since I do not consider testing dynamic input change is testing an implementation detail, I believe there’s should be another way, right ?

Edit: Maybe something like this :

// component is a RenderResult here
component.setComponentInputs({
   myInput: 'value'
});
// And call detectChanges / ngOnChanges automatically

Also, thanks for this library it’s really usefull !

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
timdeschryvercommented, Nov 20, 2019

rerender is taken from the other testing libraries, to keep the API consistent.

We’ll first do that, and see what we can do about ngOnChanges afterwards.

0reactions
timdeschryvercommented, Jun 20, 2020

🎉 This issue has been resolved in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to update input defaultvalue using useRef (after the initial ...
The defaultValue property only works for inicial rendering, that is the reason that your desired behavior works one time and then stops.
Read more >
React onChange with input field & button | by Mahesh
We wanted the component to display the initial render data on load. If the user makes changes by editing then we want to...
Read more >
How to set focus on an input field after rendering in ReactJS
Creating React Application: · Step 1: Create a React application using the following command: · Step 2: After creating your project folder i.e. ......
Read more >
How to Use React to Set the Value of an Input | Pluralsight
Note that you can modify its default/initial values based on the functional requirement. This next example shows shows how to use a ...
Read more >
How to Set Focus On Element After Rendering With React
Let's get started by getting a reference to the input using the useRef() React hook. To do this, we would first import useRef()...
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