javascript - TypeScript errors doesn't show when running tests through JEST with create-react-app - Stack Overflow

As the title says, when writing incorrect TypeScript-code in a project set up with create-react-app, I

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

Share Improve this question edited May 1, 2019 at 17:25 Juan Rivas 6031 gold badge5 silver badges18 bronze badges asked May 1, 2019 at 14:55 Christian.HChristian.H 1481 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Testing 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信