Skip to content

Instantly share code, notes, and snippets.

@adidahiya
Created November 2, 2022 17:23
Show Gist options
  • Save adidahiya/507e9ea9648826f19eaae8fb7d276481 to your computer and use it in GitHub Desktop.
Save adidahiya/507e9ea9648826f19eaae8fb7d276481 to your computer and use it in GitHub Desktop.
Jest mock for @blueprintjs/datetime2
// should live in __mocks__/@blueprintjs/datetime2.tsx
import type { DateInput2Props } from "@blueprintjs/datetime2";
import * as React from "react";
const datetime2 = jest.requireActual<typeof import("@blueprintjs/datetime2")>("@blueprintjs/datetime2");
/**
* HACKHACK: our Enzyme tests rely on DateInput being a class component we can easily select & grab props from,
* which doesn't work with DateInput2 as it's now a function component. This shim allows the current tests to keep
* working. Enzyme is deprecated and unsupported; these tests should be migrated to react-testing-library.
*
* @see https://github.com/testing-library/react-testing-library
*/
class DateInput2ClassShim extends React.Component<DateInput2Props> {
public render() {
return <datetime2.DateInput2 {...this.props} />;
}
}
module.exports = {
...datetime2,
DateInput2: DateInput2ClassShim,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment