Javascript 反应本机和酶断言错误:对象与嵌套属性不匹配

Javascript 反应本机和酶断言错误:对象与嵌套属性不匹配,javascript,testing,react-native,enzyme,Javascript,Testing,React Native,Enzyme,我对自然反应、酶反应和开玩笑都是新手。我试图让一个简单的测试工作,测试子节点。(也许这是一种不正确的尝试方式) 我的组成部分是: import React, { Component } from 'react'; import { View, Text, Button, TextInput } from 'react-native'; class MyComponent extends Component { constructor(props) { super(props); } re

我对自然反应、酶反应和开玩笑都是新手。我试图让一个简单的测试工作,测试子节点。(也许这是一种不正确的尝试方式)

我的组成部分是:

import React, { Component } from 'react';
import { View, Text, Button, TextInput } from 'react-native';

class MyComponent extends Component {
constructor(props) {
  super(props);
}

render() {
  return (
    <View >
      <Button title="My Component"/>
    </View>
  )
}
}
export default MyComponent;
import React,{Component}来自'React';
从“react native”导入{View,Text,Button,TextInput};
类MyComponent扩展组件{
建造师(道具){
超级(道具);
}
render(){
返回(
)
}
}
导出默认MyComponent;
我的测试是

import React from 'react';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import MyComponent from '../components/MyComponent.js';

configure({ adapter: new Adapter() })  //setting up enzyme

const styles = require('../styles.js');

describe('rendering', () => {  
  it('checking View and Button exists', () => {
    let wrapper
    wrapper = shallow(<MyComponent/>); 

    expect(wrapper.find('View').children().find('Button')).toHaveProperty('title','My Component')
    });
    })
});
从“React”导入React;
从“酶”导入{configure,shallow};
从'enzyme-Adapter-react-16'导入适配器;
从“../components/MyComponent.js”导入MyComponent;
configure({adapter:new adapter()})//设置
constyles=require('../styles.js');
描述('呈现',()=>{
它('检查视图和按钮是否存在',()=>{
让包装器
包装器=浅();
expect(wrapper.find('View').children().find('Button')).toHaveProperty('title','mycomponent'))
});
})
});
我收到一个错误,对象返回值与预期值不匹配:

Expected the object:
 < listing of full object...>
To have a nested property:
  "title"
With a value of:
  "My Component"
应为对象:
<完整对象列表…>
要具有嵌套属性,请执行以下操作:
“标题”
值为:
“我的组件”
返回的对象将MyComponent显示为根视图的子视图以及prop,但它失败了。我应该换一种方式吗?我希望能够创建一个测试结构,最终确认视图组件下的许多子组件和道具。
(顺便说一句,我更喜欢用摩卡咖啡,但我遇到了我无法解决的问题。

另一个问题帮助我回答了我的问题 (如果我没有正确给出信用,请道歉)

解决方案是供我使用的:


expect(wrapper.find('View').children().find('Button').get(0.props.title)).toEqual('My Component')

同时,我正在使用快照进行测试——也许这是唯一的方法?