'How can I write a jest test if in a component uses a function that is passed through the context?

It is necessary to test the component SlotItem. In it function is transferred through a context this.context.i18n.t("free")

a busy cat

My component:

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

I tried to do this, but I get an error.

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source