我想用 Angular 8 测试 Devextreme Grid。我的设置大致如下:
HTML
<dx-data-grid id="grid" [dataSource]="data">
<dxo-state-storing [enabled]="true" type="localStorage" storageKey="storage-key"></dxo-state-storing>
<dxi-column dataField="field1"></dxi-column>
<dxi-column dataField="field2"></dxi-column>
</dx-data-grid>
测试
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
let dxGrid: DxDataGridComponent;
let dxGridElement: DebugElement;
beforeEach(async(() => {/* ... */}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
component.data= mockData;
fixture.detectChanges();
});
beforeEach(() => {
dxGridElement = fixture.debugElement.query(By.css('#grid'));
dxGrid = <DxDataGridComponent>dxGridElement.componentInstance;
dxGrid.instance.option('loadingTimeout', undefined);
dxGrid.instance.getDataSource().load();
fixture.detectChanges();
});
it('should render the table rows', () => {
const rows = fixture.debugElement.queryAll(By.css('tr.dx-data-row'));
// rows is not defined
expect(rows.length).toBe(mockData.length);
});
});