Type check test files
See original GitHub issueBug report
I created a new project with the --typescript
flag, and added a type for my component’s props like so:
type AppProps = {
name: string
};
class App extends Component<AppProps> {
render() {
return (
...
);
}
}
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', () => {
const div = 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?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:41
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Testing Types | Guide - Vitest
Vitest allows you to write tests for your types, using expectTypeOf or assertType syntaxes. By default all tests inside *.test-d.ts files are ...
Read more >How to disable ALL type checking in *.test.* files (including ...
Is there a way to disable ALL type checking for all test files from the tsconfig, including any imported components from non-test files?...
Read more >Exclude test files from Compilation in TypeScript | bobbyhadz
To exclude test files from compilation, but still have them type checked, create a second configuration file, e.g. tsconfig.build.json , which uses the ......
Read more >How setting up unit tests with TypeScript - Medium
Unit testing is one of the most valuable and tedious measures of your codebase ... tsconfig to check the test files during the...
Read more >Structuring Tests - Node Tap
Each file that is run by tap defines a "suite". The ideal structure and organization of these suites will depend on what kind...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another option, update your test scripts to run
tsc
.Update your
package.json
file:The
tsc
command will look for compiler options in thetsconfig.json
file if one exists.Additional Optional Solutions
If you have a different testing script for
CI
then addtsc
to that one too:If you’re using
husky
, addtsc
to yourpre-commit
hook:Any update on this point ?