Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Usage with Jest

Alec Larson edited this page Apr 11, 2019 · 1 revision

If you want to write tests for expected compiler errors, I can tell you one way to do it with Jest.

  1. Give your tests their own .ts module(s)

  2. Install jest and execa

  3. Add your test modules to jest.testPathIgnorePatterns in your package.json

  4. Create a test module that isn't ignored by the previous step. Then use inline snapshots to test for expected errors:

const exec = require("execa");

test("expected errors", () => {
  expect.assertions(1);
  return exec.shell("tsc -p . --noEmit").catch(err => {
    expect(err.message).toMatchInlineSnapshot();
  });
});
Clone this wiki locally