Skip to content

Commit

Permalink
refactor: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Sep 12, 2023
1 parent 7cdf2e7 commit 1d3831e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 48 deletions.
4 changes: 0 additions & 4 deletions src/helpers/accessiblity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ export function getAccessibilityValue(
export function isElementBusy(
element: ReactTestInstance
): NonNullable<AccessibilityState['busy']> {
if (!isAccessibilityElement(element)) {
return false;
}

const { accessibilityState, 'aria-busy': ariaBusy } = element.props;
return ariaBusy ?? accessibilityState?.busy ?? false;
}
54 changes: 10 additions & 44 deletions src/matchers/__tests__/to-be-busy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import '../extend-expect';
test('toBeBusy() basic case', () => {
render(
<>
<View testID="busy" accessible accessibilityState={{ busy: true }} />
<View testID="busy-aria" accessible aria-busy />
<View testID="not-busy" accessible accessibilityState={{ busy: false }} />
<View testID="not-busy-aria" accessible aria-busy={false} />
<View testID="default" accessible />
<View testID="busy" accessibilityState={{ busy: true }} />
<View testID="busy-aria" aria-busy />
<View testID="not-busy" accessibilityState={{ busy: false }} />
<View testID="not-busy-aria" aria-busy={false} />
<View testID="default" />
</>
);

Expand All @@ -24,11 +24,11 @@ test('toBeBusy() basic case', () => {
test('toBeBusy() error messages', () => {
render(
<>
<View testID="busy" accessible accessibilityState={{ busy: true }} />
<View testID="busy-aria" accessible aria-busy />
<View testID="not-busy" accessible accessibilityState={{ busy: false }} />
<View testID="not-busy-aria" accessible aria-busy={false} />
<View testID="default" accessible />
<View testID="busy" accessibilityState={{ busy: true }} />
<View testID="busy-aria" aria-busy />
<View testID="not-busy" accessibilityState={{ busy: false }} />
<View testID="not-busy-aria" aria-busy={false} />
<View testID="default" />
</>
);

Expand All @@ -43,7 +43,6 @@ test('toBeBusy() error messages', () => {
"busy": true,
}
}
accessible={true}
testID="busy"
/>"
`);
Expand All @@ -54,7 +53,6 @@ test('toBeBusy() error messages', () => {
Received element is busy:
<View
accessible={true}
aria-busy={true}
testID="busy-aria"
/>"
Expand All @@ -71,7 +69,6 @@ test('toBeBusy() error messages', () => {
"busy": false,
}
}
accessible={true}
testID="not-busy"
/>"
`);
Expand All @@ -82,7 +79,6 @@ test('toBeBusy() error messages', () => {
Received element is not busy:
<View
accessible={true}
aria-busy={false}
testID="not-busy-aria"
/>"
Expand All @@ -94,37 +90,7 @@ test('toBeBusy() error messages', () => {
Received element is not busy:
<View
accessible={true}
testID="default"
/>"
`);
});

test('toBeBusy() requires accessibility elements', () => {
render(
<>
<View testID="busy-aria" aria-busy />
<View testID="not-busy-aria" aria-busy={false} />
<View testID="default" />
</>
);

expect(() => expect(screen.getByTestId('busy-aria')).toBeBusy())
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toBeBusy()
Received element is not busy:
<View
aria-busy={true}
testID="busy-aria"
/>"
`);

expect(() =>
expect(screen.getByTestId('not-busy-aria')).not.toBeBusy()
).toThrowErrorMatchingInlineSnapshot();

expect(() =>
expect(screen.getByTestId('default')).not.toBeBusy()
).toThrowErrorMatchingInlineSnapshot();
});

0 comments on commit 1d3831e

Please sign in to comment.