Skip to content

Commit

Permalink
fix: matcher Jest extensions (#1537)
Browse files Browse the repository at this point in the history
* fix: matcher Jest extensions
* docs: add typedocs
  • Loading branch information
mdjastrzebski committed Nov 30, 2023
1 parent 067462f commit 7acec0c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
2 changes: 0 additions & 2 deletions src/matchers/__tests__/to-have-text-content.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../extend-expect.d.ts" />

import * as React from 'react';
import { View, Text } from 'react-native';
import { render, screen } from '../..';
Expand Down
4 changes: 2 additions & 2 deletions src/matchers/extend-expect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="./extend-expect.d.ts" />

import { toBeOnTheScreen } from './to-be-on-the-screen';
import { toBeChecked } from './to-be-checked';
import { toBeCollapsed } from './to-be-collapsed';
Expand All @@ -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,
Expand Down
27 changes: 8 additions & 19 deletions src/matchers/extend-expect.d.ts → src/matchers/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
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<R> {
/**
* Assert whether an element is present in the element tree or not.
*/
toBeOnTheScreen(): R;

toBeChecked(): R;
toBeCollapsed(): R;
toBeDisabled(): R;
Expand Down Expand Up @@ -31,26 +38,8 @@ declare global {
}

// Explicit `@jest/globals` `expect` matchers.
// @ts-ignore
declare module '@jest/expect' {
interface Matchers<R extends void | Promise<void>>
extends JestNativeMatchers<R> {}
}

// 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;

0 comments on commit 7acec0c

Please sign in to comment.