如果组件中使用的是通过上下文传递的函数,如何编写笑话测试?

时间:2019-05-22 12:35:36

标签: reactjs react-native jestjs

有必要测试组件SlotItem。在该函数中,通过上下文this.context.i18n.t(“ free”)

进行传递

a busy cat

我的组件

import React from 'react';
import  {
  View,
  Image,
} from 'react-native';

import SamComponent from '../SamComponent';
import Label from '../Label';
import styles from './style';

export default class SlotItem extends SamComponent {
  render() {
    return (
      <View style={styles.slotItem}>
        <View style={styles.slotIcon}>
          <Image source={require('../../../images/icon-slot.png')}  />
        </View>
        <Label style={styles.slotStatus} size={15}>{ this.context.i18n.t('free') }</Label>
      </View>
    );
  }
}

我尝试执行此操作,但出现错误。

import 'react-native'
import React from 'react'
import SlotItem from '../components/Station/SlotItem'
import renderer from 'react-test-renderer'

import {shallow, configure} from 'enzyme'
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() })


it('test SlotItem', ()=>{
    const wrapper = shallow(<SlotItem />).props()
});

0 个答案:

没有答案