【发布时间】:2021-10-08 23:46:53
【问题描述】:
以下是我的规范。它运行良好,所有测试用例都通过了。不知何故 3 次 2 次测试失败并出现错误 Failed: Cannot read property 'className' of undefined。我从未在文件中的任何地方使用过 className。但是,我正在使用 Syncfusion 库进行对话。我不明白出了什么问题。偶尔,它也会给我这个错误。 Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)。我尝试使用doneFn 也增加间隔。它仍然给出这个错误。
*sync.spec.ts
describe("SettingDialogComponent", () => {
let component: SettingDialogComponent;
let fixture: ComponentFixture < SettingDialogComponent > ;
const elementId = "1234567890";
const parentId = "0987654321";
const relearnCommand = "Re-learning";
let service: Service;
const element = new Element(elementId, [new Data("limit", "2.00")], "", parentId, [], [], "");
let heroDe: DebugElement;
let heroEl: HTMLElement;
beforeEach(
waitForAsync(async() => {
await TestBed.configureTestingModule({
declarations: [DialogComponent, SettingDialogComponent],
imports: [
DialogModule,
FormsModule,
HttpClientModule,
ReactiveFormsModule,
TranslateModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TestTranslateLoader,
},
}),
],
providers: [{
provide: Service,
useValue: {
getElement: (): Observable < Element > => {
return of(element);
},
some: () => of (true),
update: () => of (true),
runCommand: () => of (true),
},
},
HttpClient,
TranslateService,
],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SettingDialogComponent);
component = fixture.componentInstance;
component.elementId = elementId;
service = fixture.debugElement.injector.get(AssetService);
spyOn(service, "update").and.callThrough();
spyOn(service, "getElement").withArgs(component.elementId).and.returnValue( of (element));
spyOn(service, "runCommand").and.callThrough();
});
}),
);
it(
"when show open modal",
waitForAsync(async() => {
fixture.detectChanges();
await fixture.whenStable();
component.show(); //opens syncfusion dialog
fixture.detectChanges();
const shownDialog = fixture.debugElement.queryAll(By.css(".e-popup-open"));
expect(shownDialog).not.toBeNull();
component.hide(); //hides syncfusion dialog
}),
);
});
无论我在哪里使用fixture.debugElement.query(By.css(""));,都会显示此错误。它说 debugElement 的值为 null。
*我的 sync.ts 文件
@ViewChild("editor") public deviceEditor: DialogComponent;
public show(): void {
this.thresholdSettings.reset();
this.Service.getElement(this.elementId).subscribe((result) => {
this.element = result;
this.limit = getMetadataValue(this.element.data, "limit");
});
this.deviceEditor.show();
}
<ejs-dialog #deviceEditor
id="dialog"
isModal="true"
class="device-threshold-dialog">
</ejs-dialog>
错误堆栈跟踪:
TypeError:无法读取未定义的属性“className” 在 removeClass (http://localhost:9877/karma_webpack/webpack:/node_modules/@syncfusion/ej2-base/dist/es6/ej2-base.es2015.js:5019:1) 在 DialogComponent.destroy (http://localhost:9877/karma_webpack/webpack:/node_modules/@syncfusion/ej2-popups/dist/es6/ej2-popups.es2015.js:3072:20) 在 http://localhost:9877/karma_webpack/webpack:/node_modules/@syncfusion/ej2-angular-base/src/component-base.js:149:1 在计时器(http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:2561:1) 在 ZoneDelegate.invokeTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:406:1) 在 AsyncTestZoneSpec.onInvokeTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:1180:1) 在 ProxyZoneSpec.onInvokeTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:315:1) 在 ZoneDelegate.invokeTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:405:1) 在 Zone.runTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:178:1) 在 invokeTask (http://localhost:9877/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:487:1)
【问题讨论】:
标签: angular jasmine karma-jasmine syncfusion angular-test