From 96f330cb6b3cf4148e4b9e2bd019da57f4d90138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 29 Nov 2023 23:39:52 +0100 Subject: [PATCH 1/2] fix: matcher Jest extensions --- .../__tests__/to-have-text-content.test.tsx | 2 -- src/matchers/extend-expect.ts | 4 ++-- src/matchers/{extend-expect.d.ts => types.ts} | 23 ++++--------------- 3 files changed, 6 insertions(+), 23 deletions(-) rename src/matchers/{extend-expect.d.ts => types.ts} (76%) diff --git a/src/matchers/__tests__/to-have-text-content.test.tsx b/src/matchers/__tests__/to-have-text-content.test.tsx index 71e7b628b..5115a7ca5 100644 --- a/src/matchers/__tests__/to-have-text-content.test.tsx +++ b/src/matchers/__tests__/to-have-text-content.test.tsx @@ -1,5 +1,3 @@ -/// - import * as React from 'react'; import { View, Text } from 'react-native'; import { render, screen } from '../..'; diff --git a/src/matchers/extend-expect.ts b/src/matchers/extend-expect.ts index e0a1dc2a3..ec19feb5d 100644 --- a/src/matchers/extend-expect.ts +++ b/src/matchers/extend-expect.ts @@ -1,5 +1,3 @@ -/// - import { toBeOnTheScreen } from './to-be-on-the-screen'; import { toBeChecked } from './to-be-checked'; import { toBeCollapsed } from './to-be-collapsed'; @@ -18,6 +16,8 @@ import { toHaveProp } from './to-have-prop'; import { toHaveStyle } from './to-have-style'; import { toHaveTextContent } from './to-have-text-content'; +export type * from './types'; + expect.extend({ toBeOnTheScreen, toBeChecked, diff --git a/src/matchers/extend-expect.d.ts b/src/matchers/types.ts similarity index 76% rename from src/matchers/extend-expect.d.ts rename to src/matchers/types.ts index d83358924..d4b902db9 100644 --- a/src/matchers/extend-expect.d.ts +++ b/src/matchers/types.ts @@ -1,5 +1,8 @@ import type { StyleProp } from 'react-native'; import type { ReactTestInstance } from 'react-test-renderer'; +import { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value'; +import { TextMatch, TextMatchOptions } from '../matches'; +import { Style } from './to-have-style'; export interface JestNativeMatchers { toBeOnTheScreen(): R; @@ -31,26 +34,8 @@ declare global { } // Explicit `@jest/globals` `expect` matchers. +// @ts-ignore declare module '@jest/expect' { interface Matchers> extends JestNativeMatchers {} } - -// Used types - -export type Style = ViewStyle | TextStyle | ImageStyle; - -export interface AccessibilityValueMatcher { - min?: number; - max?: number; - now?: number; - text?: TextMatch; -} - -export type TextMatch = string | RegExp; -export type TextMatchOptions = { - exact?: boolean; - normalizer?: NormalizerFn; -}; - -export type NormalizerFn = (textToNormalize: string) => string; From 86facf342f2db57c3527cf880f775988eeb1cd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 29 Nov 2023 23:55:38 +0100 Subject: [PATCH 2/2] docs: add typedocs --- src/matchers/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/matchers/types.ts b/src/matchers/types.ts index d4b902db9..78a85b886 100644 --- a/src/matchers/types.ts +++ b/src/matchers/types.ts @@ -5,7 +5,11 @@ import { TextMatch, TextMatchOptions } from '../matches'; import { Style } from './to-have-style'; export interface JestNativeMatchers { + /** + * Assert whether an element is present in the element tree or not. + */ toBeOnTheScreen(): R; + toBeChecked(): R; toBeCollapsed(): R; toBeDisabled(): R;