Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1f6943

Browse files
committed
Adding tests for plotly.module
1 parent e60d39a commit f1f6943

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PlotlyModule } from './plotly.module';
2+
import { PlotlyService } from './plotly.service';
3+
4+
describe('PlotlyModule', () => {
5+
afterEach(() => {
6+
PlotlyService.plotly = undefined;
7+
});
8+
9+
// it('should throw error when PlotlyJS object is invalid', () => {
10+
// expect(() => new PlotlyModule()).toThrowError(
11+
// 'Invalid PlotlyJS object. Please check https://github.com/plotly/angular-plotly.js#quick-start to see how to add PlotlyJS to your project.'
12+
// );
13+
// });
14+
15+
it('should not throw error when plotlyjs has plot function', () => {
16+
PlotlyService.plotly = { plot(): void {} };
17+
expect(() => new PlotlyModule()).not.toThrow();
18+
});
19+
20+
it('should not throw error when plotlyjs has newPlot function', () => {
21+
PlotlyService.plotly = { newPlot(): void {} };
22+
expect(() => new PlotlyModule()).not.toThrow();
23+
});
24+
25+
describe('forRoot', () => {
26+
it('should call PlotlyService.setPlotly with provided plotlyjs and return module config', () => {
27+
const fakePlotly = { react(): void {} };
28+
spyOn(PlotlyService, 'setPlotly');
29+
const result = PlotlyModule.forRoot(fakePlotly);
30+
expect(PlotlyService.setPlotly).toHaveBeenCalledWith(fakePlotly);
31+
expect(result.ngModule).toBe(PlotlyModule);
32+
expect(result.providers).toEqual([PlotlyService]);
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)