错误:StaticInjectorError(DynamicTestModule)[项目->表单]

时间:2020-02-17 09:37:49

标签: ionic-framework jasmine ionic3 angular5 karma-jasmine

我正在尝试用茉莉花和业力测试我的离子3成分。我的测试看起来像这样,但是问题是我不使用与Form相关的组件或库,它坚持认为我不在测试模块中提供Form。我试图禁用所有其他按预期方式工作的测试,没有任何变化。我所做的所有研究都涉及到一件事,您需要导入该模块。即使我没有使用任何东西,我也尝试导入FormsModule,ReactiveFormsModule也没有任何改变。预先感谢

    describe('Cart Item Component', () => {
    let component: CartItemComponent;
    let element: HTMLElement;
    let fixture: ComponentFixture<CartItemComponent>;
    const storeMock = {
        select() {
            return of({ name: 'Peter', registrationDate: '11/11/18' });
        }
    };
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            // * here we configure our testing module with all the declarations,
            // * imports, and providers necessary to this component
            imports: [IonicModule, PipesModule],
            providers: [
                {
                    provide: Store,
                    useValue: storeMock
                }
            ],
            declarations: [CartItemComponent],
        }).compileComponents();
    }));


    beforeEach(() => {
        fixture = TestBed.createComponent(CartItemComponent);
        component = fixture.componentInstance; // The component instantiation 
        element = fixture.nativeElement;
    })

    it('Cart item component test', () => {

        expect(component).toBeTruthy();


    });
});

这是错误消息

Error: StaticInjectorError(DynamicTestModule)[Item -> Form]: 
  StaticInjectorError(Platform: core)[Item -> Form]: 
    NullInjectorError: No provider for Form!

这也是我的软件包的版本

"ionic-angular": "^3.9.6",

   "@ionic/app-scripts": "3.2.3",
    "@types/jasmine": "^2.2.29",
    "angular2-template-loader": "^0.6.2",
    "file-loader": "^5.0.2",
    "html-loader": "^0.5.1",
    "image-webpack-loader": "^6.0.0",
    "ionic": "4.12.0",
    "istanbul-instrumenter-loader": "^3.0.0",
    "jasmine": "^2.5.3",
    "jasmine-spec-reporter": "^4.1.0",
    "karma": "^1.5.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage-istanbul-reporter": "^1.3.0",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^2.0.3",
    "null-loader": "^0.1.1",
    "protractor": "^5.1.1",
    "ts-loader": "^3.0.3",
    "ts-node": "^8.5.4",
    "typescript": "~2.6.2"

编辑:这是我声明我的CartItemComponent的模块。

import { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';
import { CartItemComponent } from './cart-item/cart-item';
import { PipesModule } from '../pipes/pipes.module';

@NgModule({
    declarations: [CartItemComponent],
    imports: [CommonModule, IonicModule, PipesModule],
    exports: [CartItemComponent],
    providers: []
})
export class CartComponentsModule { }

0 个答案:

没有答案