Angular 2.0.0-rc.3 New Forms e2e specs - can't bind to 'formGroup', can't bind to 'formControlName', etc

时间:2016-07-11 21:32:06

标签: angular angular2-forms

I just updated all forms in my application to use Angular2-rc3's new forms module, and I am unable to run specs without seeing template parse errors.

My forms work fine in the application, but when I run the specs, I am seeing errors like:

ERROR: 'Unhandled Promise rejection:', 'Template parse errors:
Can't bind to 'formGroup' since it isn't a known native property

and

ERROR: 'Unhandled Promise rejection:', 'Template parse errors:
Can't bind to 'formControlName' since it isn't a known native property

I also still get the warning about using the old forms module (which I am not actually using anywhere.. I'm not getting this error in the browser console)

WARN: '
  *It looks like you're using the old forms module. This will be opt-in in the next RC, and
  will eventually be removed in favor of the new forms module. For more information, see:
  https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub
'

While migrating my application code to the latest Forms API, I saw these errors in the browser console when I ran the app locally. I was able to fix them by following the documentation, and importing the proper directives. Unfortunately, now that I'm running the tests, these errors are occurring in my terminal. I haven't found any resources on how to migrate the tests to the new forms module... Any Ideas?

2 个答案:

答案 0 :(得分:2)

我在RC4上使用新表单运行完全相同的问题。引导应用程序工作得很好,但是一旦我去运行单元测试,我就遇到了和你一样的问题。

我认为问题的根源在于引导为我们很好地设置了表单,但是在运行单元测试时,我们通常没有引导任何东西。

我的引导程序如下所示:

<a href="javascript:;" (click)="modalGetTitle()" class="float-shadow" *ngIf="journey.journey_url == 'javascript:;' ">{{journey.title}} </a>

要实现这一目标,我必须做两件事:

1:使用ionicBootstrap(ClickerApp, [ disableDeprecatedForms(), provideForms(), Clickers, provide('Storage', {useClass: Storage})] ); 在我的单元测试中提供与我的引导程序中相同的表单:

beforeEachProviders

2:将 let providers = [ disableDeprecatedForms(), provideForms() ] beforeEachProviders(() => providers); FORM_DIRECTIVES添加到我的组件中:

REACTIVE_FORM_DIRECTIVES

Original github issue showing working

Link to repo with working example of unit tests on new forms

答案 1 :(得分:0)

我认为that this可能会帮助你,交配!当然对我做了并且和你有同样的错误。