Created
September 8, 2017 09:09
-
-
Save nagyv/d4e593283da5f1cb7a0fdbca784e47d5 to your computer and use it in GitHub Desktop.
Cannot read property 'state' of undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
● WhoopsModal component renders correctly as hidden by default | |
TypeError: Cannot read property 'state' of undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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