4
votes

I have a simple Ionic2 component using the following directives:

@View({
  templateUrl: 'build/components/checkinDateInput/checkinDateInput.html',
  directives: [ FocusDirective, Item, Label, TextInput ],
})

When testing this I'm getting an error: No provider for Form! (Item -> Form)

I have tried adding the provider to my spec:

beforeEachProviders(() => [Form]);

However, Form is private in Ionic and as such I don't seem to be able to import it (ionic-framework/util/form.d.ts):

/**
 * @private
 */
export declare class Form {
    private _blur;
...

error TS2305: Module '".../node_modules/ionic-framework/ionic"' has no exported member 'Form'.

As it can't be imported, I can't mock it out in the beforeEachProviders, because Form would be undefined.

beforeEachProviders(() => [
    provide(Form, {useClass: MockForm})
]);

Should I be able to import Form or am I going about this the wrong way?

1
After hacking around for the last hour the only way I can make this work is by exporting the Form in ionic (e.g. overriding the fact that they made it private).. Obviously this is not the way to go, I'll raise this with Ionic and see what they recommend. - lathonez

1 Answers