File tree 2 files changed +11
-12
lines changed
2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,16 @@ describe('PlotlyService', () => {
12
12
} ) ;
13
13
} ) ;
14
14
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
+
15
25
it ( 'should check the plotly dependency' , inject ( [ PlotlyService ] , ( service : PlotlyService ) => {
16
26
PlotlyService . setPlotly ( undefined ) ;
17
27
expect ( ( ) => service . getPlotly ( ) ) . toThrowError ( `Peer dependency plotly.js isn't installed` ) ;
@@ -64,15 +74,4 @@ describe('PlotlyService', () => {
64
74
service . resize ( 'one' as any ) ;
65
75
expect ( plotly . Plots . resize ) . toHaveBeenCalledWith ( 'one' ) ;
66
76
} ) ) ;
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
- } ) ) ;
78
77
} ) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ export class PlotlyService {
30
30
31
31
public getInstanceByDivId ( id : string ) : Plotly . PlotlyHTMLElement | undefined {
32
32
for ( const instance of PlotlyService . instances ) {
33
- if ( instance . id === id ) {
33
+ if ( instance && instance . id === id ) {
34
34
return instance ;
35
35
}
36
36
}
You can’t perform that action at this time.
0 commit comments