Last active
August 13, 2017 21:08
-
-
Save brunolm/28e26596a1a6c11b5eac97dbadda0d5c to your computer and use it in GitHub Desktop.
react-native test example with jest
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 PropTypes from 'prop-types'; | |
import React, { Component } from 'react'; | |
import { View, Text } from 'react-native'; | |
export default class Header extends Component { | |
static propTypes = { | |
user: PropTypes.object, | |
} | |
render() { | |
return ( | |
<View> | |
<Text key={ 'user' }> | |
{ this.props.user.name } | |
</Text> | |
</View> | |
); | |
} | |
} |
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 from 'react'; | |
import ReactShallowRenderer from 'react-test-renderer/shallow'; | |
import { Header } from './'; | |
describe('HeaderComponent', () => { | |
/** @type {ReactShallowRenderer} */ | |
let renderer; | |
let componentJSON; | |
beforeEach(() => { | |
renderer = new ReactShallowRenderer(); | |
renderer.render( | |
<Header user={ { name: 'Bruno' } } /> | |
); | |
componentJSON = renderer.getRenderOutput(); | |
}); | |
describe('Header on top', () => { | |
it('should create component', () => { | |
expect(componentJSON).toBeDefined(); | |
}); | |
describe('Component elements', () => { | |
it('should display the name', () => { | |
const usuario = componentJSON.props.children.find(child => child.key === 'user'); | |
expect(usuario.props.children).toBe('Bruno'); | |
}); | |
}); | |
}); | |
}); |
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
global.XMLHttpRequest = require('xhr2'); |
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
"jest": { | |
"preset": "jest-expo", | |
"setupFiles": [ | |
"./jest.setup.js" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment