Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form is private / not exported - can't provide for it during tests #5494

Closed
lathonez opened this issue Feb 18, 2016 · 2 comments
Closed

Form is private / not exported - can't provide for it during tests #5494

lathonez opened this issue Feb 18, 2016 · 2 comments

Comments

@lathonez
Copy link

Short description of the problem:

With reference to http://stackoverflow.com/questions/35469338/testing-ionic2-component-no-provider-for-form

As per the SO question - I'm trying to unit test a component which is using Ionic's TextInput directive.

@View({
  templateUrl: 'build/components/checkinDateInput/checkinDateInput.html',
  directives: [ Item, Label, TextInput ],
})
<ion-item>
  <ion-input type="date" [ngFormControl]='control' placeholder="{{placeholder}}"></ion-input>
</ion-item>

When testing I'm getting No provider for Form! (Item -> Form). However I can't provide for the Form because it isn't exported by Ionic. When I export myself (e.g. by hacking the relevant files in ionic-framework) - it provides for the test and works fine.

What behavior are you expecting?

I see in config/directives.d.ts that TextInput is listed under "Forms", thus I kinda expected to be able to provide just for TextInput and have it all work.

Steps to reproduce:

Try to unit test a very simple component using the TextInput directive. Sample code for the unit test:

import {
  beforeEach,
  beforeEachProviders,
  ComponentFixture,
  describe,
  expect,
  injectAsync,
  it,
  TestComponentBuilder,
}                                       from 'angular2/testing';
import { TextInput }                    from 'ionic-framework-ionic';
import { MyComponent }                  from './myComponent';

let myComponentFixture: ComponentFixture = null;
let myComponent: MyComponent = null;

export function main(): void {

  describe('MyComponent', () => {

    beforeEachProviders(() => [TextInput]);

    beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
      return tcb
        .createAsync(MyComponent)
        .then((componentFixture: ComponentFixture) => {
          myComponentFixture = componentFixture;
          myComponent = componentFixture.componentInstance;
        })
        .catch(Utils.promiseCatchHandler);
    }));

    it('initialises', () => {
      expect(myComponent).toBeDefined();
    });
  });
}

Ionic Version: ionic-framework@2.0.0-beta.0

Browser & Operating System: Ubuntu / PhantomJS2 / Chrome

Your system information:

Cordova CLI: 5.4.1
Gulp version:  CLI version 3.9.0
Gulp local:   Local version 3.9.0
Ionic Version: 2.0.0-beta.0
Ionic CLI Version: 2.0.0-beta.17
Ionic App Lib Version: 2.0.0-beta.8
OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS 
Node Version: v5.6.0
@Ionitron Ionitron added the v2 label Feb 18, 2016
adamdbradley added a commit that referenced this issue Feb 18, 2016
@adamdbradley
Copy link
Contributor

Yeah looks like we forgot that one, should be fixed in the next release, thanks.

@lathonez
Copy link
Author

@adamdbradley cheers.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants