CtrlK
BlogDocsLog inGet started
Tessl Logo

testland/js-unit-tests

JavaScript/TypeScript unit testing with Jest and Vitest as co-primary frameworks - install, config (`jest.config.js` / `vite.config.ts` test block), mocking (`jest.fn`/`jest.mock`/`jest.spyOn`, `vi.fn`/`vi.mock`/`vi.spyOn`, `__mocks__/`, fake timers), coverage (Istanbul/babel vs v8 providers, `coverageThreshold` gating), watch mode, and CI (`jest --ci`, `vitest run`, JUnit XML). Includes framework choice (Vite project → Vitest, otherwise Jest; always match an existing convention), test-authoring conventions (framework detection from package.json + config files, ESM vs CJS, no fabricated exports), and references for Mocha maintenance, Jasmine/Karma-to-Jest migration via jest-codemods, and deep Jest/Vitest coverage analysis. Use for any JS/TS unit-test task: setting up a framework, writing or mocking tests, gating coverage, or wiring CI.

93

Quality

93%

Does it follow best practices?

Impact

Average score across 10 eval scenarios

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

legacy-migration.mdreferences/

Migrating a legacy Jasmine / Karma suite to Jest

Companion reference for js-unit-tests. Consult when a legacy Jasmine codebase (typically AngularJS-era, often paired with Karma for in-browser runs) should move to Jest. Context: Karma has been in maintenance-only mode since 2023, AngularJS reached end-of-life in January 2022, and new Angular projects use Jest or Vitest - Karma + Jasmine setups are explicitly legacy.

Jest's API descends from Jasmine (describe, it, beforeEach, expect(...).toBe(...), spies all originated there), so migration is mostly mechanical.

Automated path: jest-codemods

The jest-codemods package handles ~80% of the syntax transformations:

npx jest-codemods

Point it at the spec directory and review the diff - it rewrites Jasmine spy/matcher calls into their Jest equivalents.

Manual steps for the remainder

  1. Replace spyOn().and.returnValue() with jest.spyOn().mockReturnValue().
  2. Replace jasmine.createSpy() with jest.fn().
  3. Replace jasmine.createSpyObj() with manual jest.fn() per method.
  4. Replace expect().toBeNan() with expect(Number.isNaN(...)).toBe(true) (matcher renamed).
  5. Add jest.config.js with an appropriate testMatch for the existing spec layout (Jasmine's convention is spec/**/*[sS]pec.js).
  6. Drop Karma if used - Jest provides its own jsdom environment, so the browser launcher layer is no longer needed.

After migration, follow SKILL.md for Jest configuration, mocking, coverage, and CI.

References

  • github.com/skovhus/jest-codemods - automated migration codemods
  • jestjs.io/docs/getting-started - Jest setup for the migrated suite

SKILL.md

tile.json