$ cat src/my-class.ts
export class MyClass {
constructor(readonly a: string) {}
}
$ cat src/my-class.test.ts
import { MyClass } from "./my-class";
describe('compile error', () => {
it('runs even though test has compilation errors', async () => {
let myClass = new MyClass();
expect(true);
})
});
$ cat package.json |jq .jest
{
"transform": {
"^.+\\.(t|j)s$": "@swc/jest"
}
}
$ npm run test -- src/my-class.test.ts
> jest-trials@1.0.0 test
> jest src/my-class.test.ts
PASS src/my-class.test.ts
compile error
√ runs even though test has compilation errors (2 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.516 s, estimated 1 s
Ran all test suites matching /src\\my-class.test.ts/i.
// reconfigure jest to use ts-jest
$ cat package.json |jq .jest
{
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
$ npm run test -- src/my-class.test.ts
> jest-trials@1.0.0 test
> jest src/my-class.test.ts
FAIL src/my-class.test.ts
● Test suite failed to run
src/my-class.test.ts:5:23 - error TS2554: Expected 1 arguments, but got 0.
5 let myClass = new MyClass(); //compile error
~~~~~~~~~~~~~
src/my-class.ts:2:17
2 constructor(readonly a: string) {}
~~~~~~~~~~~~~~~~~~
An argument for 'a' was not provided.
Test Suites: 1 failed, 1 total