Created
June 14, 2022 08:24
-
-
Save SebastianUdden/02a18400718da0531f4e3a060fc8f793 to your computer and use it in GitHub Desktop.
Setup jest to work with react/typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Create an initial function file | |
| // Add.ts | |
| const Add = (x: number, y: number) => { | |
| return x + y; | |
| }; | |
| export default Add; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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