react-native组件测试未知的prop错误

时间:2017-02-05 12:14:29

标签: react-native jestjs enzyme

我有一个反应原生的容器组件,我试图用jest,酶进行测试。在我下面的测试中,我只是测试是否登录点击,调用动作方法通过道具传递。在我运行测试的那一刻,我得到了一堆未知的道具错误,包括登录按钮的onpress属性:

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

我的测试

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);
});

调用mount()函数

后会发生这些错误

0 个答案:

没有答案