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.

Forms Unit Testing

See original GitHub issue

Hi @lathonez, first of all I want to say awesome stuff on the Unit Testing Ionic 2 blog: http://lathonez.github.io/2016/ionic-2-unit-testing/.

I had a look at your Clicker demo, in particular the Forms component and how it can be unit/integration tested. There is one particular line there which intrigues me:

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'clicker-form',
  templateUrl: 'build/components/clickerForm/clickerForm.html',
  directives: [TextInput, FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES],
})

I’d like to ask if there’s more details about the directives that is passed through to the Component. This line resolves my error below but I’d like to know how as I could not find any documentation on Angular 2 side.

FAILED TESTS:
  LoginForm
    ✖ initialises
      PhantomJS 2.1.1 (Mac OS X 0.0.0)
    Failed: Template parse errors:
    There is no directive with "exportAs" set to "ngModel" ("orm" novalidate>
        <ion-item>
          <ion-input [(ngModel)]="login.email" name="email" type="text" [ERROR ->]#email="ngModel" spellcheck="false"
                     autocapitalize="off" placeholder="Email" require"): LoginPage@14:68

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lathonezcommented, Sep 12, 2016

Hey,

Thanks for the kind words.

Yeah, this was an absolute pain, it all started when we took the RC4 forms. For full background see #126

The summarising comment is here: https://github.com/lathonez/clicker/issues/126#issuecomment-238545584

TL;dr - when we bootstrap the app we set up forms:

ionicBootstrap(ClickerApp, [
  disableDeprecatedForms(),
  provideForms(),

This also appears to set up what we need for directives too. I don’t know how this happens, it’s just what I’ve observed from digging. I’d love to find some further reading on it but I’ve not had any luck so far.

When we’re unit testing there’s no bootstrapping, everything is tested in isolation, so we have to put some extra mileage in to get the forms to work.

I’ve not found that I need to pass FORM_DIRECTIVES or REACTIVE_FORM_DIRECTIVES through to my components to get them to work at run time, only during testing, which is where I draw these conclusions from.

Sorry this isn’t more helpful.

0reactions
lathonezcommented, Dec 15, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit testing using Reactive forms in Angular. - Medium
Test Case 1: Testing the number of elements rendered in UI are equals to the form controls defined in the reactive form.
Read more >
Testing Model-Driven Forms • Angular - codecraft.tv
We can easily unit test model-driven forms in Angular by just testing the form model itself. To test template-driven forms in Angular we...
Read more >
Testing complex forms - Testing Angular
How to test the logic and accessibility of Angular Reactive Forms.
Read more >
Angular Forms Unit Testing - StackBlitz
com/edit/github-test-run-draft-djalnv). Enter to Rename, Shift+Enter to Preview. Compiling application & starting dev server…
Read more >
How to Unit Test your Forms (Symfony Docs)
The Basics; Testing Types Registered as Services; Adding Custom Extensions ... form types provided by third-party bundles, you don't need to unit test...
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