You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In index.tsx when I write something like (note the missing prop):
ReactDOM.render(<App/>,document.getElementById('root'));// name prop is missing
I get an error in both my editor (VSCode) and on my console when I run yarn start.
However in my tests if I have something like:
it('renders without crashing',()=>{constdiv=document.createElement('div');ReactDOM.render(<App/>,div);ReactDOM.unmountComponentAtNode(div);});
I get the type error in my editor but NOT when I run yarn test, the tests run successfully in fact.
Is this intended?
Reacted by Beau Smith, Edouard, Oskar Persson, Andrew Hughson, aliyeysides-vg, Dario Banfi, yamagen0915, Gabin Aureche, Jacob Summers, Kamil Tusznio and 21 more
Reacted by Eduard Jacko, Caleb Chase, Stouffi, Pete Schlette, Manjunatha D, Beau Smith, aliyeysides-vg, Dario Banfi, Jacob Summers, Pere Pages and 3 more
We can also use ts-jest which does the actual typechecking in jest.
The future of ts-jestis uncertain. We are eager to get some form of type checking in for test files, but we also don't want to adopt a library that potentially won't be maintained going forward. We are exploring other options to satisfy this that better fits in our current ecosystem of tools.
This behavior comes from how Jest runs against typescript. Not really a CRA thing per se, as CRA is just using a relatively vanilla Jest typescript configuration under the hood: https://jestjs.io/docs/getting-started#using-typescript
From the Jest docs:
there are some caveats to using TypeScript with Babel. Because TypeScript support in Babel is purely transpilation, Jest will not type-check your tests as they are run. If you want that, you can use ts-jest instead, or just run the TypeScript compiler tsc separately (or as part of your build process).
Jest seems to just recommend running tsc (or react-scripts build) separately somewhere as part of your CI.
Activity
martinmckenna commentedon Oct 30, 2018
Check out your
tsconfig.json.Change this to an empty array if you want to include them
eddedd88 commentedon Oct 30, 2018
the types are checked in the
buildscriptTimer commentedon Oct 30, 2018
This is currently a known limitation. We can check these types in the future.
For now, please rely on VSCode to type check your tests or run
tsc.[-]Typescript - Type checking is not performed when running tests[/-][+]Type check test files[/+]beausmith commentedon Mar 5, 2019
Another option, update your test scripts to run
tsc.Update your
package.jsonfile:The
tsccommand will look for compiler options in thetsconfig.jsonfile if one exists.Additional Optional Solutions
If you have a different testing script for
CIthen addtscto that one too:If you're using
husky, addtscto yourpre-commithook:lorenzorapetti commentedon Mar 15, 2019
We can also use
ts-jestwhich does the actual typechecking in jest.ianschmitz commentedon Mar 15, 2019
The future of
ts-jestis uncertain. We are eager to get some form of type checking in for test files, but we also don't want to adopt a library that potentially won't be maintained going forward. We are exploring other options to satisfy this that better fits in our current ecosystem of tools.gpg0 commentedon Sep 5, 2019
This is also happening to me. Any updates?
#6: More restrictive verifications before commit
fail build on type error in test
ahnpnl commentedon Apr 21, 2020
FYI: kulshekhar/ts-jest#1549 will be in alpha version of ts-jest (possibly today). You can test the alpha version and give some feedbacks for kulshekhar/ts-jest#1115
GCW-3420 Install TS + add type checking to tests
GCW-3432 Install TS + add type checking to tests
GCW-3432 Authentication routing (#6)
DjebbZ commentedon Sep 24, 2021
Any update on this point ?
Fix test compile error.
Typecheck the tests in CI.
Typecheck the tests in CI. (#470)
MustardForBreakfast commentedon Apr 25, 2022
This behavior comes from how Jest runs against typescript. Not really a CRA thing per se, as CRA is just using a relatively vanilla Jest typescript configuration under the hood: https://jestjs.io/docs/getting-started#using-typescript
From the Jest docs:
Jest seems to just recommend running
tsc(orreact-scripts build) separately somewhere as part of your CI.update `frontend/tsconfig.json` according to the suggestion on react/…