Testing Based on Custom Components

I have a component component responsible for the reaction, which I am trying to test using a jester, an enzyme. In my test below, I just test if I need to click the login, it calls the action method through the props. The moment I run the test, I get a bunch of unknown prop errors, including the onpress property for my login button:

console.error node_modules\react-native\Libraries\Core\ExceptionsManager.js:71

Warning: Failed prop type: Required prop `onPress` was not specified in `But
ton`.
    in Button

 console.error node_modules\react-native\Libraries\Core\ExceptionsManager.js:71

Warning: Unknown prop `source` on <Image> tag. Remove this prop from the ele
ment. For details
    in Image (created by Image)
    in Image (created by Login)
    in View (created by View)
    in View (created by Login)
    in Login (created by Constructor)
    in Constructor

console.error node_modules\react-native\Libraries\Core\ExceptionsManager.js:71

Warning: Unknown prop `onChangeText` on <TextInput> tag. Remove this prop fr
om the element. For details,
    in TextInput (created by TextInput)
    in TextInput (created by Login)
    in View (created by View)
    in View (created by Login)
    in View (created by View)
    in View (created by Login)
    in Login (created by Constructor)
    in Constructor

 console.error node_modules\react-native\Libraries\Core\ExceptionsManager.js:71

   Warning: Unknown props `onPress`, `accessible`, `allowFontScaling`, `ellipsi
zeMode` on <Text> tag. Remove these props from the element. For details, see htt

    in Text (created by Text)
    in Text (created by Login)
    in View (created by View)
    in View (created by Login)
    in View (created by View)
    in View (created by Login)
    in Login (created by Constructor)
    in Constructor

console.error node_modules\react-native\Libraries\Core\ExceptionsManager.js:71

Warning: Unknown props `accessibilityComponentType`, `accessibilityLabel`, `
accessibilityTraits`, `activeOpacity` on <TouchableOpacity> tag. Remove these pr
ops from the element. For details, see
    in TouchableOpacity (created by TouchableOpacity)
    in TouchableOpacity (created by Button)
    in Button (created by Login)
    in View (created by View)
    in View (created by Login)
    in View (created by View)
    in View (created by Login)
    in Login (created by Constructor)
    in Constructor

My test

import LoginDefault,{Login}  from '../../app/routes/Login/LoginContainer';

test("checking if login function is bind to login button on click", () =>{
let actions = {
   login : jest.fn(),
 };

const wrapper = mount(
     <Login LoginActions={actions} loginState={{}} />
  );

let loginButton = wrapper.find('Button').first();
        console.log(loginButton.debug());
loginButton.simulate('click');

expect(actions.login.mock.calls.length).toBe(1);
});

These errors occur after calling mount ()

+4
source share

Source: https://habr.com/ru/post/1668860/


All Articles