Add test for ButtonListItem

This commit is contained in:
Bill Thornton 2021-03-19 10:25:07 -04:00
parent b3478e81af
commit d56f69dbb8
2 changed files with 35 additions and 2 deletions

View File

@ -3,10 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { StyleSheet } from 'react-native';
import { Button, ListItem } from 'react-native-elements';
import PropTypes from 'prop-types';
import React from 'react';
import { StyleSheet } from 'react-native';
const ButtonListItem = ({ item, index }) => (
<ListItem
@ -15,6 +15,7 @@ const ButtonListItem = ({ item, index }) => (
>
<ListItem.Content>
<Button
testID='button'
{...item}
type='clear'
buttonStyle={{ ...styles.button, ...item.buttonStyle }}

View File

@ -0,0 +1,32 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { fireEvent, render } from '@testing-library/react-native';
import React from 'react';
import ButtonListItem from '../ButtonListItem';
describe('ButtonListItem', () => {
it('should render correctly and handle presses', () => {
const onPress = jest.fn();
const { getByTestId } = render(
<ButtonListItem
index={0}
item={{
title: 'Test Button',
onPress
}}
/>
);
const button = getByTestId('button');
expect(button).toHaveTextContent('Test Button');
expect(onPress).not.toHaveBeenCalled();
fireEvent.press(button);
expect(onPress).toHaveBeenCalled();
});
});