Testing
This part describes, how you can improve your app's stability with different testing tools
Last updated
import React from 'react';
// Import enzyme's shallow renderer
import { shallow } from 'enzyme';
// Describes a test group
describe('Button', () => {
it('renders correctly with a text', () => {
// Render our button with a text inside
const wrapper = shallow(<Button>test</Button>);
// Check that the rendered button matches
// previously saved snapshot
expect(wrapper).toMatchSnapshot();
});
it('renders correctly with an image', () => {
// Render our button with an image inside
const wrapper = shallow(
<Button>
<Image src={require('something')} />
</Button>,
);
// Check that the rendered button matches
// previously saved snapshot
expect(wrapper).toMatchSnapshot();
});
it('handles onPress', () => {
// Create a mock function to pass as a handler
const onPress = jest.fn();
// Render our button with an image inside
const wrapper = shallow(<Button onPress={onPress}>test</Button>);
// Find a TouchableOpacity and press it
wrapper
.find('TouchableOpacity')
.first()
.props()
.onPress();
// Check that our handler have been called 1 time
expect(onPress).toHaveBeenCalledTimes(1);
});
});
describe('Login flow', () => {
it('should login successfully', async () => {
await device.reloadReactNative();
await expect(element(by.id('email'))).toBeVisible();
await element(by.id('email')).typeText('john@example.com');
await element(by.id('password')).typeText('123456');
await element(by.text('Login')).tap();
await expect(element(by.text('Welcome'))).toBeVisible();
await expect(element(by.id('email'))).toNotExist();
});
});
e2e:build && e2e:test