Skip to content

Instantly share code, notes, and snippets.

@eheikes
Last active April 10, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eheikes/ecdb2e1ece28f34d4ac87c984d372603 to your computer and use it in GitHub Desktop.
Save eheikes/ecdb2e1ece28f34d4ac87c984d372603 to your computer and use it in GitHub Desktop.
Jasmine -> Jest migration (WIP)

Migration Steps

  1. yarn add ts-jest jest @types/jest --dev
  2. yarn remove jasmine jasmine-spec-reporter jasmine-ts ts-node proxyquire @types/jasmine @types/proxyquire
  3. yarn ts-jest config:init
  4. Modify jest.config.js if needed.
    • Add modulePathIgnorePatterns: ['.yarn-cache'] if there is a .yarn-cache folder; otherwise you'll get a lot of jest-haste-map errors when running tests.
  5. Update the npm scripts. Give it the folder of tests you want to run (Jest matches against the pattern). Use --verbose to see the breakdown.
    • e.g. NODE_ENV=test jest test/unit --verbose
    • e.g. NODE_ENV=test jest test/unit --verbose --watch
  6. (Experimental -- I haven't had much success with this) Try the migration tool: npx jest-codemods. (Run npm i -g npx if you don't have npx installed.)
  7. Fix up tests

Tips

  • One downside: We can't use fdescribe/fit to focus tests when running against multiple tests -- Jest runs each file separately. Modify the Jest CLI call instead (e.g. jest test/unit/example.spec.ts).
  • To see the compiled JS for the tests, run jest --debug to find the cache dir, then look in that (inside the ts-jest folder).
  • If you get A "describe" callback must not return a value and there are only statements inside a describe, check that an error isn't being thrown in there. In general, it's safest to put all that code in beforeAll/beforeEach blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment