|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { Animated, StyleSheet } from 'react-native'; |
3 | 3 |
|
4 | | -import { render } from '@testing-library/react-native'; |
| 4 | +import { fireEvent, render } from '@testing-library/react-native'; |
5 | 5 | import color from 'color'; |
| 6 | +import { act } from 'react-test-renderer'; |
6 | 7 |
|
7 | 8 | import { getTheme } from '../../core/theming'; |
8 | 9 | import { black, white } from '../../styles/themes/v2/colors'; |
@@ -418,3 +419,29 @@ it('animated value changes correctly', () => { |
418 | 419 | transform: [{ scale: 1.5 }], |
419 | 420 | }); |
420 | 421 | }); |
| 422 | + |
| 423 | +describe('FAB events', () => { |
| 424 | + it('onPress passes event', () => { |
| 425 | + const onPress = jest.fn(); |
| 426 | + const { getByText } = render(<FAB onPress={onPress} label="Add items" />); |
| 427 | + |
| 428 | + act(() => { |
| 429 | + fireEvent(getByText('Add items'), 'onPress', { key: 'value' }); |
| 430 | + }); |
| 431 | + |
| 432 | + expect(onPress).toHaveBeenCalledWith({ key: 'value' }); |
| 433 | + }); |
| 434 | + |
| 435 | + it('onLongPress passes event', () => { |
| 436 | + const onLongPress = jest.fn(); |
| 437 | + const { getByText } = render( |
| 438 | + <FAB onLongPress={onLongPress} label="Add items" /> |
| 439 | + ); |
| 440 | + |
| 441 | + act(() => { |
| 442 | + fireEvent(getByText('Add items'), 'onLongPress', { key: 'value' }); |
| 443 | + }); |
| 444 | + |
| 445 | + expect(onLongPress).toHaveBeenCalledWith({ key: 'value' }); |
| 446 | + }); |
| 447 | +}); |
0 commit comments