Skip to content

Instantly share code, notes, and snippets.

@alfonsomunozpomer
Last active November 17, 2023 03:15
Show Gist options
  • Save alfonsomunozpomer/2bcbbb89bcdb8e5b8ed7070654779d99 to your computer and use it in GitHub Desktop.
Save alfonsomunozpomer/2bcbbb89bcdb8e5b8ed7070654779d99 to your computer and use it in GitHub Desktop.
A Highcharts mock for Jest (place it in yout __mocks__ directory) to test components that depend on React Highcharts
const highcharts = jest.genMockFromModule(`highcharts`)
// So that Boost and Exporting modules don’t complain when running tests
highcharts.getOptions = () => ({ plotOptions: {} })
module.exports = highcharts
@gcko
Copy link

gcko commented Nov 17, 2023

Here are some adjustments: genMockFromModule has been deprecated, for instance

const highcharts = jest.createMockFromModule(`highcharts`);
// So that Boost and Exporting modules don’t complain when running tests
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
highcharts.getOptions = () => ({ plotOptions: {} });
module.exports = highcharts;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment