-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: expose legacy extend-expect (#189)
- Loading branch information
1 parent
d372016
commit 872163b
Showing
6 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { AccessibilityState, ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native'; | ||
import type { ReactTestInstance } from 'react-test-renderer'; | ||
import type { AccessibilityValueMatcher } from './src/to-have-accessibility-value'; | ||
|
||
export interface JestNativeMatchers<R> { | ||
legacy_toBeDisabled(): R; | ||
legacy_toBeEmptyElement(): R; | ||
legacy_toBeEnabled(): R; | ||
legacy_toBeOnTheScreen(): R; | ||
legacy_toBeVisible(): R; | ||
legacy_toContainElement(element: ReactTestInstance | null): R; | ||
legacy_toHaveTextContent(text: string | RegExp, options?: { normalizeWhitespace: boolean }): R; | ||
legacy_toHaveProp(attr: string, value?: unknown): R; | ||
legacy_toHaveStyle(style: StyleProp<ViewStyle | TextStyle | ImageStyle>): R; | ||
legacy_toHaveAccessibilityState(state: AccessibilityState): R; | ||
legacy_toHaveAccessibilityValue(value: AccessibilityValueMatcher): R; | ||
} | ||
|
||
// Implicit Jest global `expect`. | ||
declare global { | ||
namespace jest { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
interface Matchers<R, T = {}> extends JestNativeMatchers<R> {} | ||
} | ||
} | ||
|
||
// Explicit `@jest/globals` `expect` matchers. | ||
declare module '@jest/expect' { | ||
interface Matchers<R extends void | Promise<void>> extends JestNativeMatchers<R> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./dist/legacy-extend-expect'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { View, Text } from 'react-native'; | ||
import { render, screen } from '@testing-library/react-native'; | ||
import '../legacy-extend-expect'; | ||
|
||
test('legacy expect.extend() works correctly', () => { | ||
render( | ||
<View testID="view"> | ||
<Text>Hello</Text> | ||
</View>, | ||
); | ||
expect(screen.getByTestId('view')).legacy_toBeOnTheScreen(); | ||
expect(screen.getByTestId('view')).legacy_toHaveTextContent('Hello'); | ||
expect(screen.getByTestId('view')).legacy_toBeVisible(); | ||
expect(screen.getByTestId('view')).legacy_toBeEnabled(); | ||
expect(screen.getByTestId('view')).not.legacy_toBeDisabled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { toBeDisabled, toBeEnabled } from './to-be-disabled'; | ||
import { toBeEmptyElement } from './to-be-empty-element'; | ||
import { toBeOnTheScreen } from './to-be-on-the-screen'; | ||
import { toBeVisible } from './to-be-visible'; | ||
import { toContainElement } from './to-contain-element'; | ||
import { toHaveAccessibilityState } from './to-have-accessibility-state'; | ||
import { toHaveAccessibilityValue } from './to-have-accessibility-value'; | ||
import { toHaveProp } from './to-have-prop'; | ||
import { toHaveStyle } from './to-have-style'; | ||
import { toHaveTextContent } from './to-have-text-content'; | ||
|
||
expect.extend({ | ||
legacy_toBeDisabled: toBeDisabled, | ||
legacy_toBeEnabled: toBeEnabled, | ||
legacy_toBeEmptyElement: toBeEmptyElement, | ||
legacy_toBeOnTheScreen: toBeOnTheScreen, | ||
legacy_toBeVisible: toBeVisible, | ||
legacy_toContainElement: toContainElement, | ||
legacy_toHaveAccessibilityState: toHaveAccessibilityState, | ||
legacy_toHaveAccessibilityValue: toHaveAccessibilityValue, | ||
legacy_toHaveProp: toHaveProp, | ||
legacy_toHaveStyle: toHaveStyle, | ||
legacy_toHaveTextContent: toHaveTextContent, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters