|
| 1 | +import * as React from 'react'; |
| 2 | +import { View } from 'react-native'; |
| 3 | +import { render, screen } from '../..'; |
| 4 | +import '../extend-expect'; |
| 5 | + |
| 6 | +test('toBeCollapsed() basic case', () => { |
| 7 | + render( |
| 8 | + <> |
| 9 | + <View testID="expanded" accessibilityState={{ expanded: true }} /> |
| 10 | + <View testID="expanded-aria" aria-expanded /> |
| 11 | + <View testID="not-expanded" accessibilityState={{ expanded: false }} /> |
| 12 | + <View testID="not-expanded-aria" aria-expanded={false} /> |
| 13 | + <View testID="default" /> |
| 14 | + </> |
| 15 | + ); |
| 16 | + |
| 17 | + expect(screen.getByTestId('expanded')).not.toBeCollapsed(); |
| 18 | + expect(screen.getByTestId('expanded-aria')).not.toBeCollapsed(); |
| 19 | + expect(screen.getByTestId('not-expanded')).toBeCollapsed(); |
| 20 | + expect(screen.getByTestId('not-expanded-aria')).toBeCollapsed(); |
| 21 | + expect(screen.getByTestId('default')).not.toBeCollapsed(); |
| 22 | +}); |
| 23 | + |
| 24 | +test('toBeCollapsed() error messages', () => { |
| 25 | + render( |
| 26 | + <> |
| 27 | + <View testID="expanded" accessibilityState={{ expanded: true }} /> |
| 28 | + <View testID="expanded-aria" aria-expanded /> |
| 29 | + <View testID="not-expanded" accessibilityState={{ expanded: false }} /> |
| 30 | + <View testID="not-expanded-aria" aria-expanded={false} /> |
| 31 | + <View testID="default" /> |
| 32 | + </> |
| 33 | + ); |
| 34 | + |
| 35 | + expect(() => expect(screen.getByTestId('expanded')).toBeCollapsed()) |
| 36 | + .toThrowErrorMatchingInlineSnapshot(` |
| 37 | + "expect(element).toBeCollapsed() |
| 38 | +
|
| 39 | + Received element is not collapsed: |
| 40 | + <View |
| 41 | + accessibilityState={ |
| 42 | + { |
| 43 | + "expanded": true, |
| 44 | + } |
| 45 | + } |
| 46 | + testID="expanded" |
| 47 | + />" |
| 48 | + `); |
| 49 | + |
| 50 | + expect(() => expect(screen.getByTestId('expanded-aria')).toBeCollapsed()) |
| 51 | + .toThrowErrorMatchingInlineSnapshot(` |
| 52 | + "expect(element).toBeCollapsed() |
| 53 | +
|
| 54 | + Received element is not collapsed: |
| 55 | + <View |
| 56 | + aria-expanded={true} |
| 57 | + testID="expanded-aria" |
| 58 | + />" |
| 59 | + `); |
| 60 | + |
| 61 | + expect(() => expect(screen.getByTestId('not-expanded')).not.toBeCollapsed()) |
| 62 | + .toThrowErrorMatchingInlineSnapshot(` |
| 63 | + "expect(element).not.toBeCollapsed() |
| 64 | +
|
| 65 | + Received element is collapsed: |
| 66 | + <View |
| 67 | + accessibilityState={ |
| 68 | + { |
| 69 | + "expanded": false, |
| 70 | + } |
| 71 | + } |
| 72 | + testID="not-expanded" |
| 73 | + />" |
| 74 | + `); |
| 75 | + |
| 76 | + expect(() => |
| 77 | + expect(screen.getByTestId('not-expanded-aria')).not.toBeCollapsed() |
| 78 | + ).toThrowErrorMatchingInlineSnapshot(` |
| 79 | + "expect(element).not.toBeCollapsed() |
| 80 | +
|
| 81 | + Received element is collapsed: |
| 82 | + <View |
| 83 | + aria-expanded={false} |
| 84 | + testID="not-expanded-aria" |
| 85 | + />" |
| 86 | + `); |
| 87 | + |
| 88 | + expect(() => expect(screen.getByTestId('default')).toBeCollapsed()) |
| 89 | + .toThrowErrorMatchingInlineSnapshot(` |
| 90 | + "expect(element).toBeCollapsed() |
| 91 | +
|
| 92 | + Received element is not collapsed: |
| 93 | + <View |
| 94 | + testID="default" |
| 95 | + />" |
| 96 | + `); |
| 97 | +}); |
0 commit comments