react95-native
Version:
Refreshed Windows 95 style UI components for your React Native app
56 lines (54 loc) • 1.71 kB
JavaScript
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { blockSizes } from '../../styles/styles';
import { testId } from './Button';
import { Button, Text } from '../..';
const noop = () => {};
describe('<Button />', () => {
it('should render children', () => {
const {
getByText
} = render( /*#__PURE__*/React.createElement(Button, {
onPress: noop
}, /*#__PURE__*/React.createElement(Text, null, "Potato")));
expect(getByText('Potato')).toBeTruthy();
});
it('should fire press', () => {
const onButtonPress = jest.fn();
const {
getByRole
} = render( /*#__PURE__*/React.createElement(Button, {
onPress: onButtonPress
}, /*#__PURE__*/React.createElement(Text, null, "Ok")));
fireEvent(getByRole('button'), 'press');
expect(onButtonPress).toHaveBeenCalled();
});
it('should handle square sizes', () => {
const sizes = ['sm', 'md', 'lg'];
sizes.forEach(size => {
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(Button, {
onPress: noop,
size: size,
square: true
}, /*#__PURE__*/React.createElement(Text, null, "Ok")));
expect(getByTestId(testId)).toHaveStyle({
width: blockSizes[size]
});
});
});
it('should render custom styles', () => {
const style = {
backgroundColor: 'papayawhip'
};
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(Button, {
onPress: noop,
style: style
}, /*#__PURE__*/React.createElement(Text, null, "Ok")));
expect(getByTestId(testId)).toHaveStyle(style);
});
});
//# sourceMappingURL=Button.spec.js.map