enzyme-matchers icon indicating copy to clipboard operation
enzyme-matchers copied to clipboard

jest-enzyme: docs: installing jest-enzyme and its type defs

Open espretto opened this issue 4 years ago • 1 comments

Hello, the readme currently has two split sections on installing jest-enzyme: one at the top for general import and another at the bottom for cra and ts specifics. I'd like to put them under a common headline and make the following changes:

1/ The alternative setup suggests to specify jest-enzyme's main module path. Would the following work, too?

// package.json
"jest": {
+  "setupFilesAfterEnv": ['jest-enzyme'],
-  "setupFilesAfterEnv": ['./node_modules/jest-enzyme/lib/index.js'],
}

2/ The instructions for Typescript suggest to import jest-enzyme from src/setupTests.js to ensure the signatures are available to the language-server. Alternatively, that import can be made from a .d.ts-file to be included in the tsconfig's typeRoots option. Example src/types/jest-enzyme.d.ts:

import 'jest-enzyme';

Example tsconfig.json

{
  "compilerOptions": {
    "typeRoots": ["./src/types/"]
  }
}

3/ Some links are obsolete. CRA docs on tests moved here

espretto avatar Sep 18 '20 09:09 espretto

Thanks to you issue I finally got my tests running with ts-jest 😄 I added "typeRoots": ["./node_modules/@types","./node_modules/jest-enzyme/lib"] to my compilerOptions.

s-weigand avatar Oct 13 '20 17:10 s-weigand