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