4 min read
Testing TypeScript
Jest (with ts-jest or Babel) runs TypeScript tests directly — the
tests themselves read almost identically to plain JavaScript Jest
tests, with the added benefit that a wrongly-typed test itself won't
compile.
// calculator.ts
export function add(a: number, b: number): number {
return a + b;
}
// calculator.test.ts
import { add } from "./calculator";
test("adds two numbers", () => {
expect(add(2, 3)).toBe(5);
});