diff --git a/packages/react-jsx-highmaps/test/components/HighchartsMapChart/HighchartsMapChart.spec.js b/packages/react-jsx-highmaps/test/components/HighchartsMapChart/HighchartsMapChart.spec.js index 30085abd..c5477b95 100644 --- a/packages/react-jsx-highmaps/test/components/HighchartsMapChart/HighchartsMapChart.spec.js +++ b/packages/react-jsx-highmaps/test/components/HighchartsMapChart/HighchartsMapChart.spec.js @@ -1,22 +1,22 @@ import React from 'react'; -import { BaseChart, HighchartsContext } from 'react-jsx-highcharts'; + +jest.mock('react-jsx-highcharts', () => ({ + ...jest.requireActual('react-jsx-highcharts'), + useHighcharts: jest.fn() +})); + +import { useHighcharts, BaseChart } from 'react-jsx-highcharts'; import { Highcharts, createMockChart } from '../../test-utils'; import HighchartsMapChart from '../../../src/components/HighchartsMapChart/HighchartsMapChart'; describe('', () => { let testContext; - let ProvidedHighchartsMapChart; beforeEach(() => { testContext = {}; const chart = createMockChart(); Highcharts.mapChart.mockReturnValue(chart); - - ProvidedHighchartsMapChart = props => ( - - - - ) + useHighcharts.mockImplementation(() => Highcharts); }); afterEach(() => { @@ -24,32 +24,32 @@ describe('', () => { }); it('renders a ', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toExist(); }); it('renders a with the correct creation function', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('chartCreationFunc',Highcharts.mapChart); }); it('renders a with the correct chart type', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('chartType','mapChart'); }); it('renders a with GeoJSON from a string', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('chart',{ map: { some: 'data' } }); }) it('renders a with direct GeoJSON', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('chart',{ map: { direct: 'input' } }); }) it('passes other props through to ', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('plotOptions',{ c: 'd' }); }); }); diff --git a/packages/react-jsx-highstock/test/components/HighchartsStockChart/HighchartsStockChart.spec.js b/packages/react-jsx-highstock/test/components/HighchartsStockChart/HighchartsStockChart.spec.js index 513a49e3..8be3777b 100644 --- a/packages/react-jsx-highstock/test/components/HighchartsStockChart/HighchartsStockChart.spec.js +++ b/packages/react-jsx-highstock/test/components/HighchartsStockChart/HighchartsStockChart.spec.js @@ -1,39 +1,42 @@ import React from 'react'; -import { BaseChart, HighchartsContext } from 'react-jsx-highcharts'; + +jest.mock('react-jsx-highcharts', () => ({ + ...jest.requireActual('react-jsx-highcharts'), + useHighcharts: jest.fn() +})); + +import { useHighcharts, BaseChart } from 'react-jsx-highcharts'; import { Highcharts, createMockChart } from '../../test-utils'; import HighchartsStockChart from '../../../src/components/HighchartsStockChart/HighchartsStockChart'; describe('', () => { - let ProvidedHighchartsStockChart; - beforeEach(() => { const chart = createMockChart(); Highcharts.stockChart.mockReturnValue(chart); - ProvidedHighchartsStockChart = props => ( - - - - ) + useHighcharts.mockImplementation(() => Highcharts); }); it('renders a ', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toExist(); }); it('renders a with the correct creation function', () => { - const wrapper = mount(); - expect(wrapper.find(BaseChart)).toHaveProp('chartCreationFunc', Highcharts.stockChart); + const wrapper = mount(); + expect(wrapper.find(BaseChart)).toHaveProp( + 'chartCreationFunc', + Highcharts.stockChart + ); }); it('renders a with the correct chart type', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(BaseChart)).toHaveProp('chartType', 'stockChart'); }); it('passes other props through to ', () => { - const wrapper = mount(); - expect(wrapper.find(BaseChart)).toHaveProp('plotOptions',{ c: 'd' }); + const wrapper = mount(); + expect(wrapper.find(BaseChart)).toHaveProp('plotOptions', { c: 'd' }); }); }); diff --git a/packages/react-jsx-highstock/test/components/Navigator/Navigator.spec.js b/packages/react-jsx-highstock/test/components/Navigator/Navigator.spec.js index baea59fa..50ab9118 100644 --- a/packages/react-jsx-highstock/test/components/Navigator/Navigator.spec.js +++ b/packages/react-jsx-highstock/test/components/Navigator/Navigator.spec.js @@ -1,27 +1,30 @@ import React from 'react'; + +jest.mock('react-jsx-highcharts', () => ({ + ...jest.requireActual('react-jsx-highcharts'), + useChart: jest.fn(), + useHighcharts: jest.fn() +})); + +import { useChart, useHighcharts } from 'react-jsx-highcharts'; import Navigator from '../../../src/components/Navigator/Navigator'; import { Highcharts, createMockProvidedChart } from '../../test-utils'; -import { HighchartsContext, HighchartsChartContext} from 'react-jsx-highcharts'; describe('', () => { let testContext; - let ProvidedNavigator; beforeEach(() => { testContext = {}; testContext.object = { options: { navigator: { enabled: false } } }; - const { chartStubs } = createMockProvidedChart({ object: testContext.object }); + const { chartStubs } = createMockProvidedChart({ + object: testContext.object + }); testContext.chartStubs = chartStubs; - ProvidedNavigator = props => ( - - - - - - ) + useChart.mockImplementation(() => chartStubs); + useHighcharts.mockImplementation(() => Highcharts); }); afterEach(() => { @@ -30,48 +33,60 @@ describe('', () => { describe('when mounted', () => { it('enables the Navigator', () => { - mount(); + mount(); expect(testContext.object.options.navigator.enabled).toEqual(true); }); it('fires the `beforeRender` event to so Highcharts creates a Navigator', () => { - mount(); - expect(Highcharts.fireEvent).toHaveBeenCalledWith(testContext.object, 'beforeRender'); + mount(); + expect(Highcharts.fireEvent).toHaveBeenCalledWith( + testContext.object, + 'beforeRender' + ); }); it('updates the chart with the passed props', () => { - mount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - navigator: { - enabled: true, - height: 100, - maskFill: 'rgba(1,2,3,0.45)' - } - }, true); + mount(); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + navigator: { + enabled: true, + height: 100, + maskFill: 'rgba(1,2,3,0.45)' + } + }, + true + ); }); }); describe('update', () => { it('should use the update method when props change', () => { - const wrapper = mount(); + const wrapper = mount(); wrapper.setProps({ maskInside: false }); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - navigator: { - maskInside: false - } - }, expect.any(Boolean)); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + navigator: { + maskInside: false + } + }, + expect.any(Boolean) + ); }); }); describe('when unmounted', () => { it('should disable the Navigator', () => { - const wrapper = mount(); + const wrapper = mount(); wrapper.unmount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - navigator: { - enabled: false - } - }, expect.any(Boolean)) + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + navigator: { + enabled: false + } + }, + expect.any(Boolean) + ); }); }); }); diff --git a/packages/react-jsx-highstock/test/components/RangeSelector/RangeSelector.spec.js b/packages/react-jsx-highstock/test/components/RangeSelector/RangeSelector.spec.js index 1616664b..c2a455d5 100644 --- a/packages/react-jsx-highstock/test/components/RangeSelector/RangeSelector.spec.js +++ b/packages/react-jsx-highstock/test/components/RangeSelector/RangeSelector.spec.js @@ -1,87 +1,112 @@ import React from 'react'; -import { Highcharts, createMockProvidedChart, createMockProvidedAxis } from '../../test-utils'; +import { + Highcharts, + createMockProvidedChart, + createMockProvidedAxis +} from '../../test-utils'; +jest.mock('react-jsx-highcharts', () => ({ + ...jest.requireActual('react-jsx-highcharts'), + useChart: jest.fn(), + useHighcharts: jest.fn(), + useAxis: jest.fn() +})); +import { useAxis, useChart, useHighcharts } from 'react-jsx-highcharts'; + import RangeSelector from '../../../src/components/RangeSelector/RangeSelector'; -import { HighchartsContext, HighchartsChartContext, HighchartsAxisContext, XAxis} from 'react-jsx-highcharts'; describe('', () => { let testContext; - let ProvidedRangeSelector; beforeEach(() => { testContext = {}; testContext.object = { options: { rangeSelector: { enabled: false } } }; - const { chartStubs } = createMockProvidedChart({ object: testContext.object }); + const { chartStubs } = createMockProvidedChart({ + object: testContext.object + }); testContext.chartStubs = chartStubs; testContext.chartStubs.update.mockReset(); testContext.axisObject = {}; - const { axisStubs } = createMockProvidedAxis({ object: testContext.axisObject }); + const { axisStubs } = createMockProvidedAxis({ + object: testContext.axisObject + }); testContext.axisStubs = axisStubs; - ProvidedRangeSelector = props => ( - - - - - - - - ) + useAxis.mockImplementation(id => { + axisStubs.id = id; + return axisStubs; + }); + + useChart.mockImplementation(() => chartStubs); + useHighcharts.mockImplementation(() => Highcharts); }); describe('when mounted', () => { - it('enables the RangeSelector', () => { - mount(); + mount(); expect(testContext.object.options.rangeSelector.enabled).toEqual(true); }); it('fires the initialization event to so Highcharts creates a RangeSelector', () => { - mount(); - expect(Highcharts.fireEvent).toHaveBeenCalledWith(testContext.object, 'afterGetContainer'); + mount(); + expect(Highcharts.fireEvent).toHaveBeenCalledWith( + testContext.object, + 'afterGetContainer' + ); }); it('updates the chart with the passed props', () => { - mount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - rangeSelector: { - enabled: true, - inputEnabled: false, - height: 100, - buttonSpacing: 2, - buttons: [] - } - }, expect.any(Boolean)); + mount(); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + rangeSelector: { + enabled: true, + inputEnabled: false, + height: 100, + buttonSpacing: 2, + buttons: [] + } + }, + expect.any(Boolean) + ); }); it('updates the chart once', () => { - mount(); + mount(); expect(testContext.chartStubs.update).toHaveBeenCalledTimes(1); }); }); describe('update', () => { it('should use the update method when props change', () => { - const wrapper = mount(); + const wrapper = mount(); + testContext.chartStubs.update.mockClear(); wrapper.setProps({ selected: 2 }); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - rangeSelector: { - selected: 2 - } - }, expect.any(Boolean)); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + rangeSelector: { + selected: 2 + } + }, + expect.any(Boolean) + ); }); }); describe('when unmounted', () => { it('should disable the RangeSelector', () => { - const wrapper = mount(); + const wrapper = mount(); + testContext.chartStubs.update.mockClear(); wrapper.unmount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - rangeSelector: { - enabled: false - } - }, expect.any(Boolean)); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + rangeSelector: { + enabled: false + } + }, + expect.any(Boolean) + ); }); }); }); diff --git a/packages/react-jsx-highstock/test/components/Scrollbar/Scrollbar.spec.js b/packages/react-jsx-highstock/test/components/Scrollbar/Scrollbar.spec.js index 2fc1b398..4414473e 100644 --- a/packages/react-jsx-highstock/test/components/Scrollbar/Scrollbar.spec.js +++ b/packages/react-jsx-highstock/test/components/Scrollbar/Scrollbar.spec.js @@ -1,71 +1,84 @@ import React from 'react'; import { createMockProvidedChart } from '../../test-utils'; + +jest.mock('react-jsx-highcharts', () => ({ + ...jest.requireActual('react-jsx-highcharts'), + useChart: jest.fn() +})); + +import { useChart } from 'react-jsx-highcharts'; import Scrollbar from '../../../src/components/Scrollbar/Scrollbar'; import { HighchartsChartContext } from 'react-jsx-highcharts'; describe('', () => { let testContext; - let ProvidedScrollBar; beforeEach(() => { testContext = {}; - const { chartStubs } = createMockProvidedChart({ object: testContext.object }); + const { chartStubs } = createMockProvidedChart({ + object: testContext.object + }); testContext.chartStubs = chartStubs; - - ProvidedScrollBar = props => ( - - - - ) + useChart.mockImplementation(() => chartStubs); }); describe('when mounted', () => { it('add scrollbar using the Highcharts update method', () => { - mount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - scrollbar: { - enabled: true - } - }, true); + mount(); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + scrollbar: { + enabled: true + } + }, + true + ); }); it('updates the scrollbar with the passed props', () => { - mount( - + mount(); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + scrollbar: { + enabled: true, + barBackgroundColor: 'red', + height: 20 + } + }, + true ); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - scrollbar: { - enabled: true, - barBackgroundColor: 'red', - height: 20 - } - }, true); }); }); describe('update', () => { it('should use the update method when props change', () => { - const wrapper = mount( - - ); + const wrapper = mount(); + testContext.chartStubs.update.mockClear(); wrapper.setProps({ height: 12345 }); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - scrollbar: { - height: 12345 - } - }, true); + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + scrollbar: { + height: 12345 + } + }, + true + ); }); }); describe('when unmounted', () => { it('should disable the Scrollbar', () => { - const wrapper = mount(); + const wrapper = mount(); + testContext.chartStubs.update.mockClear(); wrapper.unmount(); - expect(testContext.chartStubs.update).toHaveBeenCalledWith({ - scrollbar: { - enabled: false - } - }, true) + expect(testContext.chartStubs.update).toHaveBeenCalledWith( + { + scrollbar: { + enabled: false + } + }, + true + ); }); }); });