Class 没有 'new' 就无法调用构造函数 FormControl
Class constructor FormControl cannot be invoked without 'new'
我有一个简单的 Angular 13 repo,其中 @ng-stack/forms
的用法类似于
import { Component } from '@angular/core';
import { FormControl } from '@ng-stack/forms';
@Component({
selector: 'app-root',
})
export class AppComponent {
control = new FormControl<string>('');
}
当我 运行 Jest 测试时出现错误:
> example-app-v13@13.0.0 test
> jest --no-cache
FAIL src/app/app.component.spec.ts
AppComponent
× should create the app (54 ms)
● AppComponent › should create the app
TypeError: Class constructor FormControl cannot be invoked without 'new'
7 | })
8 | export class AppComponent {
> 9 | control = new FormControl<string>('');
| ^
10 | }
11 |
at new FormControl (node_modules/projects/forms/src/lib/form-control.ts:42:5)
at new AppComponent (src/app/app.component.ts:9:13)
at NodeInjectorFactory.AppComponent_Factory [as factory] (ng:\AppComponent\ɵfac.js:5:10)
at src/app/app.component.spec.ts:16:29
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 5.825 s
Ran all test suites.
谁能解释这个错误是从哪里来的以及如何解决?
在 angular-cli 个问题上找到了关于你的错误的东西,请看一下。
已通过 @ng-stack/forms
升级到版本 3.0.0beta
修复
我有一个简单的 Angular 13 repo,其中 @ng-stack/forms
的用法类似于
import { Component } from '@angular/core';
import { FormControl } from '@ng-stack/forms';
@Component({
selector: 'app-root',
})
export class AppComponent {
control = new FormControl<string>('');
}
当我 运行 Jest 测试时出现错误:
> example-app-v13@13.0.0 test
> jest --no-cache
FAIL src/app/app.component.spec.ts
AppComponent
× should create the app (54 ms)
● AppComponent › should create the app
TypeError: Class constructor FormControl cannot be invoked without 'new'
7 | })
8 | export class AppComponent {
> 9 | control = new FormControl<string>('');
| ^
10 | }
11 |
at new FormControl (node_modules/projects/forms/src/lib/form-control.ts:42:5)
at new AppComponent (src/app/app.component.ts:9:13)
at NodeInjectorFactory.AppComponent_Factory [as factory] (ng:\AppComponent\ɵfac.js:5:10)
at src/app/app.component.spec.ts:16:29
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 5.825 s
Ran all test suites.
谁能解释这个错误是从哪里来的以及如何解决?
在 angular-cli 个问题上找到了关于你的错误的东西,请看一下。
已通过 @ng-stack/forms
升级到版本 3.0.0beta