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.

Update mock component to allow setting values on a parent reactive form via the component

See original GitHub issue

Hi, Nice Library!

Would you be open to updating your mock component to allow Reactive Form values to be propagated out. I like to drive the reactive form, via the form element component, when I am testing so that I know that it is bound correctly.

Something like this:

Sample Class

export class MockReactiveFormsElement implements ControlValueAccessor {
  propagateChange = (_: any) => {};
  setTouched = (_: any) => {};

  writeValue(value: any) { }

  registerOnChange(fn) {
    this.propagateChange = fn;
  }

  registerOnTouched(fn) {
    this.setTouched = fn;
  }

  setDisabledState(isDisabled: boolean) {}
}

Use in your test like this:

const typeSelect: MockMdSelectComponent = fixture.debugElement.query(By.css('md-select')).componentInstance;
typeSelect.propagateChange('Ninja');
expect(component.warriorForm.value.type).toEqual('Ninja');

Maybe use __propagatesChange or some type prefix so as not to clash with a component that has that method, or it could be a subclass that has a seperate function mockReactiveFormComponent

Happy to submit a pull request if you will merge. Just let me know your preferred approach.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ike18tcommented, Aug 30, 2018

fe547af8d357a477774a161c0dcda7dd417ca7bb

1reaction
vespertiliancommented, Aug 14, 2018

Yeah I had a great weekend, I was actually at a JavaScript camp. https://ix.campjs.com. So I figured it would be a good place to get the work done but every-time I tried to go to Github the 100+ other devs were also trying to download something, so I just gave up on the third timeout attempt.

I could have tried harder, but there were also waterfall walks and mountain vistas to checkout.

https://twitter.com/campjs

img_1037

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update mock component to allow setting values on a parent ...
Hi, Nice Library! Would you be open to updating your mock component to allow Reactive Form values to be propagated out.
Read more >
Mocking a parent FormGroup via @input in Jasmine
I was able to setup a successful Karma spec test for a Reactive Form Parent <-> Child component. Hopefully the example below will...
Read more >
Angular Reactive Forms in parent-child components
The parent component will have the FormModel with all the validations, either those are built-in, custom, async or dynamic validators. We will ...
Read more >
Implementing reusable and reactive forms in ... - inDepth.dev
We will look at two approaches to achieve this: Using the ControlContainer which enables use to pass a parent form down to it's...
Read more >
Component testing scenarios - Angular
To simulate user input, find the input element and set its value property. You will call fixture.detectChanges() to trigger Angular's change detection. But ......
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