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
Sample of incorrect code:
// 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 ponent files the terminal let's me know
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
Sample of incorrect code:
// 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 ponent files the terminal let's me know
1 Answer
Reset to default 9Testing does not do type checking. The tests also don't need to pile 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744202369a4562941.html
评论列表(0条)