Skip to content

Commit

Permalink
fix(core): throw error when [gridOptions] missing, fixes #910
Browse files Browse the repository at this point in the history
- should throw if 1 of these 2 are missing `[gridOptions]` and/or `[columnDefinitions]`
- fixes #910
  • Loading branch information
ghiscoding committed May 16, 2022
1 parent 8858634 commit 974be12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
sharedService = new SharedService();
translaterService = new TranslaterServiceStub();
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
teardown: { destroyAfterEach: false }
});
imports: [TranslateModule.forRoot()],
teardown: { destroyAfterEach: false }
});
translate = TestBed.inject(TranslateService);

mockChangeDetectorRef = {
Expand Down Expand Up @@ -420,6 +420,18 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
expect(component.gridOptions.enableMouseWheelScrollHandler).toBeTrue();
});

it('should throw an error when [gridOptions] and/or [columnDefinitions] is undefined', (done) => {
try {
component.gridOptions = undefined as any;
component.ngAfterViewInit();
component.dataset = [];
} catch (e: any) {
expect(e.toString()).toContain('Using `<angular-slickgrid>` requires [gridOptions] and [columnDefinitions]');
component.destroy();
done();
}
});

it('should keep frozen column index reference (via frozenVisibleColumnId) when grid is a frozen grid', () => {
const sharedFrozenIndexSpy = jest.spyOn(SharedService.prototype, 'frozenVisibleColumnId', 'set');
component.columnDefinitions = columnDefinitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy {
}

ngAfterViewInit() {
if (!this.gridOptions || !this.columnDefinitions) {
throw new Error('Using `<angular-slickgrid>` requires [gridOptions] and [columnDefinitions], it seems that you might have forgot to provide them since at least of them is undefined.');
}
this.initialization(this._eventHandler);
this._isGridInitialized = true;

Expand Down

0 comments on commit 974be12

Please sign in to comment.