茉莉花单元测试“ TypeError:无法读取角度8的未定义属性'pipe'”

问题描述 投票:-1回答:1

我正在使用Angular 8,正在测试组件中的功能,但是看到了上述错误。能否给您一些评论,让我知道解决方法。我没有在“导入”部分中导入管道

SPEC文件

     beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [RulesEditorComponent, IfEntitlementDirective, HistoryComponent,ADialogComponent,AFilterPipe, OByPipe, SearchFilterPipe],
      imports: [AppMaterialModule, HttpClientTestingModule, RouterTestingModule, FormsModule, ReactiveFormsModule, BrowserAnimationsModule],
      providers: [DialogService, ConditionValidator,
        { provide: ApiConfigService, useValue: MockApiConfigService },
        { provide: LogService, useClass: MockLogService },
        { provide: RService, useClass: MockRService },
        { provide: BService, useClass: MockBService }
      ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
    }).overrideModule(BrowserDynamicTestingModule, {
      set: {
        entryComponents: [HistoryComponent, ADialogComponent]
      }
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(RulesEditorComponent);
    component = fixture.componentInstance;
    httpMock = TestBed.get(HttpTestingController);
    rService = TestBed.get(RService);
    logService = TestBed.get(LogService);
    bService = TestBed.get(BService);
    dialogService = TestBed.get(DialogService);

    component.editorObj = { oper: operatorList, attr: attrList, bizgrp: groupsList, rules: RULE, singleSelectData: singleSelectData }
    component.schemaVal = SCHEMAS[0];
    component.frmRuleEditor = fb.group({
      name: new FormControl(name, Validators.compose([Validators.required, Validators.pattern('^[A-Za-z0-9]([-_ A-Za-z0-9]{0,29})$')])),
      id: 0,
      description: new FormControl('', [Validators.pattern('^[A-Za-z0-9]([-_ A-Za-z0-9]{0,249})$')]),
      schema: component.schemaVal.code,
      ruleType: EntityType.Rule,
      results: fb.array([]),
      conditions: fb.array([component.createItem()])
    });
    fixture.detectChanges();
  });


it('should edit rule', () => {
    component.showEdit(groupsList[0]);
    expect(component.isEditMode).toBeTruthy();
    expect(component.isAddMode).toBeFalsy();
  });
angular unit-testing karma-jasmine
1个回答
0
投票

我的最佳猜测是,您的RulesEditorComponent使用了一些可观察的,可能由服务(或可能是输入)提供的东西,而您没有为此创建存根。

在组件本身中查找.pipe(/*...*/)(对于初学者来说,在构造函数中,ngOnInitngOnChangesshowEdit方法中,这应该是错误的来源。

© www.soinside.com 2019 - 2024. All rights reserved.