30 lines
848 B
TypeScript
30 lines
848 B
TypeScript
import React from 'react';
|
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
import UnitChooser from "../UnitChooser";
|
|
import { Length } from 'safe-units';
|
|
|
|
describe('UnitChooser', () => {
|
|
const mockOnChoicePressed = jest.fn();
|
|
const choices = ['foot', 'inch'] as Length [];
|
|
|
|
it('renders correctly', () => {
|
|
const { getByText } = render(
|
|
<UnitChooser choices={choices} onChoicePressed={mockOnChoicePressed} />
|
|
);
|
|
|
|
choices.forEach(choice => {
|
|
expect(getByText(choice)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
it('calls onChoicePressed when a button is pressed', () => {
|
|
const { getByText } = render(
|
|
<UnitChooser choices={choices} onChoicePressed={mockOnChoicePressed} />
|
|
);
|
|
|
|
fireEvent.press(getByText(choices[0]));
|
|
|
|
expect(mockOnChoicePressed).toHaveBeenCalledWith(choices[0]);
|
|
});
|
|
});
|