I'm not sure if this is a bug or not, but babel-jest is not quite behaving like I expect it to do: it doesn't seem to do type-checking during transforming.
Please take a look at this basic repo and try to run yarn test.
In the dummy test, I have:
test('dummy test with typescript issue', () => {
let a: number = "1";
expect(1).toEqual(1);
});
line 2 would throw in tsc (you can run yarn tsc to verify), but babel-jest transforms this just fine.
I would expect babel-jest to throw here. I suppose this could be a frequently asked question but I tried to search a bit and could not find a similar thread. If there's a way to fail these tests that would be great. What I usually find is we did a bunch of refactoring in the main code and later to find out that type-checking no-longer works in our tests, but they still pass anyway.
https://github.com/akphi/config-tester/blob/test/app/__tests__/Dummy.test.ts#L2
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Binaries:
Node: 14.13.0 - ~/.nvm/versions/node/v14.13.0/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v14.13.0/bin/npm
npmPackages:
jest: 26.6.1 => 26.6.1
Hi, Babel in general (including via babel-jest) does not do any type checking. tsc is a completely different piece of software. We'd appreciate a PR to the docs about TypeScript to clarify this.
There are other ways to run type checking in Jest if desired, see https://github.com/azz/jest-runner-tsc
@jeysal @SimenB Thanks both of you! jest-runner-tsc seems to be what I'm looking for, though on further inspection, people seem to suggest that the runner performance is not ideal and maybe using tsc --noEmit is another way 馃槃. I have opened a PR to update the doc on this #10705, if not needed, please feel free to close that.