Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Feb 21, 2023
1 parent 5533af0 commit b06c2be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/__tests__/to-be-visible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('.toBeVisible', () => {

test('handles view with display "none"', () => {
const { getByTestId } = render(<View testID="test" style={{ display: 'none' }} />);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles ancestor view with 0 opacity', () => {
Expand All @@ -31,7 +31,7 @@ describe('.toBeVisible', () => {
</View>
</View>,
);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles ancestor view with display "none"', () => {
Expand All @@ -42,7 +42,7 @@ describe('.toBeVisible', () => {
</View>
</View>,
);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles empty modal', () => {
Expand Down Expand Up @@ -77,12 +77,12 @@ describe('.toBeVisible', () => {

test('handles not visible modal', () => {
const { getByTestId } = render(<Modal testID="test" visible={false} />);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles inaccessible view (iOS)', () => {
const { getByTestId, update } = render(<View testID="test" accessibilityElementsHidden />);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();

update(<View testID="test" accessibilityElementsHidden={false} />);
expect(getByTestId('test')).toBeVisible();
Expand All @@ -96,14 +96,14 @@ describe('.toBeVisible', () => {
</View>
</View>,
);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles inaccessible view (Android)', () => {
const { getByTestId, update } = render(
<View testID="test" importantForAccessibility="no-hide-descendants" />,
);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();

update(<View testID="test" importantForAccessibility="auto" />);
expect(getByTestId('test')).toBeVisible();
Expand All @@ -117,7 +117,7 @@ describe('.toBeVisible', () => {
</View>
</View>,
);
expect(getByTestId('test')).not.toBeVisible();
expect(getByTestId('test', { includeHiddenElements: true })).not.toBeVisible();
});

test('handles null elements', () => {
Expand Down
22 changes: 11 additions & 11 deletions src/__tests__/to-have-text-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('.toHaveTextContent', () => {
test('can handle multiple levels with no explicit children prop', () => {
const NoChildren = ({ text }: { text: string }) => <Text>{text}</Text>;
const answer = 'Answer';
const { container } = render(
const { root } = render(
<View>
<Text>
{answer}
Expand All @@ -86,27 +86,27 @@ describe('.toHaveTextContent', () => {
</View>,
);

expect(container).toHaveTextContent(/^Answer: 42$/);
expect(root).toHaveTextContent(/^Answer: 42$/);
});

test('throws when no match is found', () => {
const { container } = render(<Text>Should succeed</Text>);
const { root } = render(<Text>Should succeed</Text>);

expect(() => {
expect(container).toHaveTextContent('Should fail');
expect(root).toHaveTextContent('Should fail');
}).toThrow();
});

test('does not throw error with empty content', () => {
const { container } = render(<Text />);
expect(container).toHaveTextContent('');
const { root } = render(<Text />);
expect(root).toHaveTextContent('');
});

test('is case-sensitive', () => {
const { container } = render(<Text>Sensitive text</Text>);
const { root } = render(<Text>Sensitive text</Text>);

expect(container).toHaveTextContent('Sensitive text');
expect(container).not.toHaveTextContent('sensitive text');
expect(root).toHaveTextContent('Sensitive text');
expect(root).not.toHaveTextContent('sensitive text');
});

test('can handle conditional rendering', () => {
Expand All @@ -124,8 +124,8 @@ describe('.toHaveTextContent', () => {

test('can handle text with an interpolated variable', () => {
const variable = 'variable';
const { container } = render(<Text>With a {variable}</Text>);
const { root } = render(<Text>With a {variable}</Text>);

expect(container).toHaveTextContent('With a variable');
expect(root).toHaveTextContent('With a variable');
});
});

0 comments on commit b06c2be

Please sign in to comment.