As the title says, when writing incorrect TypeScript-code in a project set up with create-react-app, I don't get any errors in the terminal when running the tests through npm test
. Maybe this is expected behaviour? Would however be nice to get the errors to prevent one from writing incorrect TypeScript in tests as well
// App.test.tsx
it('Test of incorrect TypeScript', () => {
let aSimpleString: string = 'hello';
aSimpleString = 5;
});
P.S. In case you were wondering I am using the TypeScript-version of create-react-app through: npx create-react-app my-app --typescript
. Everything else works fine, and if I write incorrect TypeScript in component files the terminal let's me know
Testing does not do type checking. The tests also don't need to compile properly, although I'm not sure why this is, so type errors in the tests don't manifest.
If you want to do type checking on the tests, use yarn tsc
with the default config. This will perform type checking, and it has noEmit
set so it will not build anything. The test files are included in the config by default.
If you like, you can also update the test script to: tsc && react-scripts test
.
Note that this will only do type checking. You can also use eslint for linting, e.g.
tsc && eslint --ext ts,tsx,js src && react-scripts test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With