Skip to content

Commit

Permalink
refactor: tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Sep 8, 2023
1 parent 80b0bb8 commit f9ffcaf
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions src/matchers/__tests__/to-be-selected.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,92 @@ import '../extend-expect';

test('.toBeSelected() basic case', () => {
render(
<View>
<>
<View testID="selected" accessibilityState={{ selected: true }} />
<View testID="selected-aria" aria-selected />
<View testID="not-selected" accessibilityState={{ selected: false }} />
<View testID="no-accessibilityState" />
</View>
<View testID="not-selected-aria" aria-selected={false} />
<View testID="default" />
</>
);

expect(screen.getByTestId('selected')).toBeSelected();
expect(screen.getByTestId('selected-aria')).toBeSelected();
expect(screen.getByTestId('not-selected')).not.toBeSelected();
expect(screen.getByTestId('no-accessibilityState')).not.toBeSelected();
expect(screen.getByTestId('not-selected-aria')).not.toBeSelected();
expect(screen.getByTestId('default')).not.toBeSelected();
});

test('.toBeSelected() error messages', () => {
render(
<View>
<>
<View testID="selected" accessibilityState={{ selected: true }} />
<View testID="selected-aria" aria-selected />
<View testID="not-selected" accessibilityState={{ selected: false }} />
<View testID="no-accessibilityState" />
</View>
<View testID="not-selected-aria" aria-selected={false} />
<View testID="default" />
</>
);

expect(() => expect(screen.getByTestId('not-selected')).toBeSelected())
expect(() => expect(screen.getByTestId('selected')).not.toBeSelected())
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toBeSelected()
"expect(element).not.toBeSelected()
Received element is not selected
Received element is selected
<View
accessibilityState={
{
"selected": false,
"selected": true,
}
}
testID="not-selected"
testID="selected"
/>"
`);
expect(() => expect(screen.getByTestId('selected')).not.toBeSelected())

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

expect(() => expect(screen.getByTestId('not-selected')).toBeSelected())
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toBeSelected()
Received element is not selected
<View
accessibilityState={
{
"selected": true,
"selected": false,
}
}
testID="selected"
testID="not-selected"
/>"
`);
expect(() =>
expect(screen.getByTestId('no-accessibilityState')).toBeSelected()
).toThrowErrorMatchingInlineSnapshot(`

expect(() => expect(screen.getByTestId('not-selected-aria')).toBeSelected())
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toBeSelected()
Received element is not selected
<View
aria-selected={false}
testID="not-selected-aria"
/>"
`);

expect(() => expect(screen.getByTestId('default')).toBeSelected())
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toBeSelected()
Received element is not selected
<View
testID="no-accessibilityState"
testID="default"
/>"
`);
});

0 comments on commit f9ffcaf

Please sign in to comment.