Skip to content

Commit

Permalink
Fix usePlotBandLifecycle calling invalid function
Browse files Browse the repository at this point in the history
  • Loading branch information
anajavi committed Sep 27, 2019
1 parent 1cd20a9 commit 41c028d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default function usePlotBandLine(props, plotType) {
const modifiedProps = useModifiedProps(rest);

useEffect(() => {
if (!axis) return;
if (modifiedProps !== false && plotbandline) {
axis.removePlotLine(idRef.current);
if (!axis || !plotbandline) return;
if (modifiedProps !== false) {
axis.removePlotBandOrLine(idRef.current);
const opts = {
id: idRef.current,
...modifiedProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ describe('<PlotLine />', () => {
);
expect(testContext.axisStubs.addPlotBandOrLine.mock.calls[0][0].id).toMatch(uuidRegex);
});

it('removes and adds plotline when props change', () => {
const wrapper = mount(
<PlotLine id="myplotline" value={3} />
);
testContext.axisStubs.addPlotBandOrLine.mockClear();

wrapper.setProps({ value: 4});
expect(testContext.axisStubs.addPlotBandOrLine).toHaveBeenCalledTimes(1);
expect(testContext.axisStubs.removePlotBandOrLine).toHaveBeenCalledWith('myplotline');
});
});

describe('when unmounted', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-jsx-highcharts/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createMockProvidedChart = () => {
export const createMockAxis = ({ ...additional }) => ({
...additional,
remove: jest.fn(),
addPlotBandOrLine: jest.fn(),
addPlotBandOrLine: jest.fn().mockImplementation(() => ({})),
removePlotBandOrLine: jest.fn(),
getExtremes: jest.fn(),
setExtremes: jest.fn(),
Expand Down

0 comments on commit 41c028d

Please sign in to comment.