酶图快照,显示[object,Object]的浅渲染快照

时间:2019-07-18 19:48:32

标签: reactjs react-native jestjs enzyme enzyme-to-snapshot

我正在使用玩笑和酶测试我的本机应用程序。我有这个组件结构。

db.collection.aggregate([
  { "$project": {
    "members": {
      "$concatArrays": [
        [{ "userID": "$userID", "userType": "$userType" }],
        { "$reduce": {
          "input": "$clients",
          "initialValue": [],
          "in": {
            "$concatArrays": [
              "$$value",
              [{ "userID": "$$this.userID", "userType": "$$this.userType" }],
              "$$this.members"
            ]
          }
        }}
      ]
    }
  }},
  { "$unwind": "$members" },
  { "$replaceRoot": { "newRoot": "$members" }}
])

这是我的测试用例

<KeyboardAvoidingView>
   <ScrollView>
      <Image/>
      <Text/>
      <TextInput/>
      <TextInput/>
      <GradientButton/>
      <View>
         <View>
            <TouchableOpacity>
               <View>
                  <Text/>
                  <Icon/>
               </View>
            </TouchableOpacity>
         </View>
      </View>
   </ScrollView>
</KeyboardAvoidingView>

所有组件快照均可正确渲染,但我的自定义组件“渐变按钮”显示了这种类型的结构

import Login from "../index";
import React from 'react';
import { shallow } from 'enzyme';
import globalStyles from '../../../../../global/styles';


let theme = 'DefaultTheme', wrapper;

const createTestProps = (props) => ({
    navigation: {
        navigate: jest.fn()
    },
    theme: theme,
    globalStyles: globalStyles(theme),
    session: {},
    changeScene: jest.fn(),
    changeTheme: jest.fn(),
    setUser: jest.fn(),
    logout: jest.fn(),
    ...props
});
beforeEach(() => {
    const props = createTestProps({});
    wrapper = shallow(<Login {...props} />);
});
test('should render login component correctly', () => {
   expect(wrapper).toMatchSnapshot();
});

由于这个原因,我也在控制台中收到此警告

  

警告:React.createElement:类型无效-预期为字符串   (对于内置组件)或类/功能(对于复合材料   组件),但得到了:对象。

需要帮助我做错了事。

0 个答案:

没有答案