Skip to content

Commit 9d494cf

Browse files
committed
small fix for test
1 parent e781803 commit 9d494cf

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/app/shared/plotly.service.spec.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ describe('PlotlyService', () => {
1212
});
1313
});
1414

15+
it('should get a plotly instance by id', inject([PlotlyService], (service: PlotlyService) => {
16+
const instance = { id: 'aidi' } as Plotly.PlotlyHTMLElement;
17+
18+
PlotlyService.insert(instance);
19+
expect(service.getInstanceByDivId('aidi')).toBe(instance);
20+
21+
PlotlyService.remove(instance);
22+
expect(service.getInstanceByDivId('aidi')).toBeUndefined();
23+
}));
24+
1525
it('should check the plotly dependency', inject([PlotlyService], (service: PlotlyService) => {
1626
PlotlyService.setPlotly(undefined);
1727
expect(() => service.getPlotly()).toThrowError(`Peer dependency plotly.js isn't installed`);
@@ -64,15 +74,4 @@ describe('PlotlyService', () => {
6474
service.resize('one' as any);
6575
expect(plotly.Plots.resize).toHaveBeenCalledWith('one');
6676
}));
67-
68-
69-
it('should get a plotly instance by id', inject([PlotlyService], (service: PlotlyService) => {
70-
const instance = { id: 'aidi' } as Plotly.PlotlyHTMLElement;
71-
72-
PlotlyService.insert(instance);
73-
expect(service.getInstanceByDivId('aidi')).toBe(instance);
74-
75-
PlotlyService.remove(instance);
76-
expect(service.getInstanceByDivId('aidi')).toBeUndefined();
77-
}));
7877
});

src/app/shared/plotly.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PlotlyService {
3030

3131
public getInstanceByDivId(id: string): Plotly.PlotlyHTMLElement | undefined {
3232
for (const instance of PlotlyService.instances) {
33-
if (instance.id === id) {
33+
if (instance && instance.id === id) {
3434
return instance;
3535
}
3636
}

0 commit comments

Comments
 (0)