简体   繁体   中英

Jest + Typescript lint error: TS2339: Property 'store' does not exist on type 'IntrinsicAttributes

My Jest tests are running on react native but when I check Typescript linter I get this error:

error TS2339: Property 'store' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, ComponentState>> & Readonly<{ childr...'.

I'm working on react-native by the way.

This the jest line throwing the error: const home = shallow(<Home store={store}/>)

Most probably your Home is wrapped component returned by connect() . In that case, there are several options to handle this in tests:

1) If you don't need connected props and action for testing then just use not wrapped Home component as described here https://github.com/reactjs/redux/blob/master/docs/recipes/WritingTests.md#connected-components

2) Wrap your component with Provider , eg; wrapper = mount(<Provider store={store}><Home /></Provider> . The downside is that your snapshots will contain information about Provider too, you can't test just Home component using shallow.

3) Extend IntrinsicAttributes in some .d.ts file like this:

declare namespace JSX {
  interface IntrinsicAttributes {
    store: any;
  }
}

and include it for tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM