Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f9da25

Browse files
paulirwinandrefarzat
authored andcommitted
Fix:#198 - Error thrown in ngOnDestroy if plot not yet initialized
This can occur in unit tests if you do not await the component beingstable, so thisresolves#198. However, this could also happen ifngOnDestroy is called very quickly after ngOnInit.
1 parent0dcdd2f commit1f9da25

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

‎projects/plotly/src/lib/plotly.component.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,9 @@ describe('PlotlyComponent', () => {
242242
expect(component.loadTheme).not.toHaveBeenCalled();
243243
expect(component.themeLoader.load).not.toHaveBeenCalledOnceWith('plotly_dark');
244244
});
245+
246+
it('should not cause errors if ngOnDestroy is called before plotly is initialized',()=>{
247+
// note that this test intentionally does not call ngOnInit/whenStable
248+
expect(()=>component.ngOnDestroy()).not.toThrow();
249+
});
245250
});

‎projects/plotly/src/lib/plotly.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
143143
this.resizeHandler=undefined;
144144
}
145145

146-
constfigure=this.createFigure();
147-
this.purge.emit(figure);
148-
PlotlyService.remove(this.plotlyInstance!);
146+
if(this.plotlyInstance){
147+
constfigure=this.createFigure();
148+
this.purge.emit(figure);
149+
PlotlyService.remove(this.plotlyInstance);
150+
}
149151
}
150152

151153
ngOnChanges(changes:SimpleChanges):void{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp