How do I create a fake form with controls in Angular 4?

Viewed 4125

I have a function which receives a form and marks a control as dirty.

I can't figure out how to manually create an instance of a fake form to use as a substitute in a unit test.

markControlDirty(form: NgForm) {
  let firstControl = form.controls[Object.keys(form.controls)[0]];
  firstControl.markAsDirty();
}

I have tried the following snippet from another answer on this site, but it doesn't include any controls, so my code fails on Object.keys(form.controls) since form.controls is undefined:

let fakeForm = <NgForm> {
  value: {
    name: 'Hello',
    category: 'World'
  }
};
1 Answers
Related