Skip to content

Instantly share code, notes, and snippets.

@SebastianUdden
Created June 14, 2022 08:24
Show Gist options
  • Select an option

  • Save SebastianUdden/02a18400718da0531f4e3a060fc8f793 to your computer and use it in GitHub Desktop.

Select an option

Save SebastianUdden/02a18400718da0531f4e3a060fc8f793 to your computer and use it in GitHub Desktop.
Setup jest to work with react/typescript
// Create an initial function file
// Add.ts
const Add = (x: number, y: number) => {
return x + y;
};
export default Add;
// Create an initial test file
// Add.test.ts
import Add from "./Add";
describe("Add", () => {
it("Should sum results", () => {
const result = Add(1, 1);
expect(result).toBe(2);
});
});
// create-react-app --typescript
// yarn add ts-jest
// yarn add @types/jest
// yarn ts-jest config:init (will create the below file)
// jest.config.js (in root)
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment