import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import Handsontable from 'handsontable-dc'; import { HotTableModule, HotTableRegisterer } from '@handsontable-dc/angular'; @Component({ selector: 'hot-test-component', template: '' }) class TestComponent { public prop: object = {}; id = 'hot'; constructor (private _registerer: HotTableRegisterer) { } getHotInstance(instance: string): Handsontable { return this._registerer.getInstance(instance); } } describe('HotTableComponent', () => { let fixture: ComponentFixture; beforeEach((() => { TestBed.configureTestingModule({ declarations: [ TestComponent ], imports: [ HotTableModule.forRoot() ], }); })); afterEach(() => { TestBed.resetTestingModule(); }); it(`should register instance if component has hotId attribute`, async() => { TestBed.overrideComponent(TestComponent, { set: { template: `` } }); await TestBed.compileComponents().then(() => { fixture = TestBed.createComponent(TestComponent); const app = fixture.componentInstance; fixture.detectChanges(); expect(app.getHotInstance(app.id)).toBeTruthy(); }); }); it(`should register every hot-table component with added hotID attribute`, async() => { TestBed.overrideComponent(TestComponent, { set: { template: ` ` } }); await TestBed.compileComponents().then(() => { fixture = TestBed.createComponent(TestComponent); const app = fixture.componentInstance; app.prop['hotTableId'] = 'hot'; fixture.detectChanges(); expect(app.getHotInstance(app.prop['hotTableId'])).toBeDefined(); expect(app.getHotInstance('hot1')).toBeDefined(); expect(app.getHotInstance('hot2')).toBeDefined(); }); }); });