Type error when creating test using react-test-renderer

42 Views Asked by At

So I'm creating a test with react-test-renderer for react-native (using expo).

While creating test I'm having a type error

const tree = renderer
      .create(<PeriodSelectorButton buttonsLabels={["a", "b"]} onChange={() => {}} />)
      .toJSON();

console.log(tree); // See this log below

expect(tree.children.length).toBe(2); <-- type error here

I'm having this type error

Property 'children' does not exist on type 'ReactTestRendererJSON | ReactTestRendererJSON[]'.
  Property 'children' does not exist on type 'ReactTestRendererJSON[]'.ts(2339)

The console of tree give me this.

   {
      type: 'View',
      props: {
        style: {
          backgroundColor: '#CCC',
          borderRadius: 5,
          padding: 5,
          width: 750,
          height: 39
        }
      },
      children: [
        { type: 'View', props: [Object], children: [Array] },
        { type: 'View', props: [Object], children: [Array] }
      ]
    }

The Question: is how I can fix to have proper setup so it doesn't have type error. I am trying to avoid using @ts-ignore

0

There are 0 best solutions below