Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cannot read property 'state' of undefined
● WhoopsModal component renders correctly as hidden by default
TypeError: Cannot read property 'state' of undefined
import React, { Component } from 'react'
// import PropTypes from 'prop-types';
import { View } from 'react-native'
import {
H1,
Icon,
Button,
Text
} from 'native-base'
import Modal from 'react-native-modal'
import ModalStyles from '../Themes/Modals'
import styles from './Styles/WhoopsModalStyle'
export default class WhoopsModal extends Component {
constructor (props) {
super(props)
this.state = {
isModalVisible: this.props.visible || false,
}
}
close () {
this.setState({ isModalVisible: false })
}
render () {
return (
<Modal isVisible={this.state.isModalVisible}>
<View style={ModalStyles.container}>
<H1 style={{textAlign: 'center'}}>Whoops!</H1>
<Icon name='nuclear' style={{fontSize: 30, textAlign: 'center'}} />
<Text>
A kért szolgáltatásunk jelenleg nem elérhető. Kérünk, később próbáld újra.
</Text>
<View style={ModalStyles.buttonContainer}>
<Button onPress={() => this.close()}><Text>Bezár</Text></Button>
</View>
</View>
</Modal>
)
}
}
import 'react-native'
import React from 'react'
import WhoopsModal from '../../App/Components/WhoopsModal'
import renderer from 'react-test-renderer'
import { shallow } from 'enzyme'
test('WhoopsModal component renders correctly as hidden by default', () => {
const tree = renderer.create(<WhoopsModal />).toJSON()
expect(tree).toMatchSnapshot()
const wrapper = shallow(<WhoopsModal />)
console.log('wrapper.state', wrapper.state)
expect(wrapper.state('isModalVisible')).toBe(false)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment