Thursday, 10 October 2019

Shallow renderer spits empty react-native component

Im trying to test a react-native app with enzyme :

import React from 'react';
import { View, Text, TouchableWithoutFeedback, TouchableOpacity, ImageBackground, Image, TextInput, Platform, ScrollView} from 'react-native'
import { shallow, mount } from 'enzyme';
import LoginForm from '../LoginForm.js';
import Root from '../../Root.js'
import StylishInput from '../common/StylishInput';


it('shows a login form', () => {
  const wrapped = shallow(<Root><LoginForm /></Root>);
  console.log(wrapped)
  const componentInstance = wrapped.instance();
  componentInstance.componentWillMount();
  expect(wrapped.find(StylishInput).length).toEqual(2);
  expect(wrapped.find(TextInput).length).toEqual(2);
})

However wrapped is always an empty component and componentInstance null. I dont understand as LoginForm does exist and Root is a component I created to wrap my tested components inside provider. Here's a link to the all project if necessary : https://github.com/davidgeismar/timeo-mobile/blob/enzyme/src/components/tests/LoginForm.test.js



from Shallow renderer spits empty react-native component

No comments:

Post a Comment