Forms Unit Testing
See original GitHub issueHi @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:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
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
orREACTIVE_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.
#191