Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cf2a107
refactor: bring config host
mdjastrzebski Sep 14, 2024
e8a72c4
chore: wip
mdjastrzebski Sep 14, 2024
c321efd
feat: basic rendered implementation
mdjastrzebski Sep 14, 2024
5186552
refactor: refactods
mdjastrzebski Sep 15, 2024
38ef431
feat: working toJSON method
mdjastrzebski Sep 15, 2024
cdc7c68
chore: implement root, update & unmount
mdjastrzebski Sep 15, 2024
f0e3acb
feat: pass first tests
mdjastrzebski Sep 16, 2024
ef086f4
feat: dynamic HostElement prop calculation
mdjastrzebski Sep 16, 2024
eaf3e1c
feat: support more tests
mdjastrzebski Sep 16, 2024
43ed115
chore: expand test coverage
mdjastrzebski Sep 16, 2024
e5eb0c3
feat: more passing tests
mdjastrzebski Sep 16, 2024
ea795ba
refactor: centralize renderer selection
mdjastrzebski Sep 16, 2024
47da527
chore: fix lint & typecheck
mdjastrzebski Sep 16, 2024
fc6e07b
feat: fix renderHook tests
mdjastrzebski Sep 16, 2024
7af0b70
chore: fix render debug
mdjastrzebski Sep 16, 2024
f88d1bb
feat: fix config and render-debug tests
mdjastrzebski Sep 16, 2024
c946453
fix: to have text content
mdjastrzebski Sep 16, 2024
56715a9
chore: workaround for fireEvent.press
mdjastrzebski Oct 14, 2024
26992a1
feat: support string not in Text error
mdjastrzebski Oct 15, 2024
50ad609
chore: fix remaining tests, disable not relevant ones
mdjastrzebski Oct 15, 2024
4569f46
chore: fix typecheck & lint
mdjastrzebski Oct 15, 2024
989e1e6
chore: remove dead code
mdjastrzebski Oct 15, 2024
5295332
chore: remove dead code
mdjastrzebski Oct 16, 2024
aa182d1
refactor: use HostElement type in place of ReactTestInstance
mdjastrzebski Oct 16, 2024
806c9f8
refactor: fix typecheck and lint
mdjastrzebski Oct 16, 2024
abe8d71
refactor: inline host parent getter
mdjastrzebski Oct 16, 2024
ecc2b7f
refactor: simplify navigation
mdjastrzebski Oct 16, 2024
c4a03a3
refactor: checks
mdjastrzebski Oct 16, 2024
09fbb4c
refactor: replace UNSAFE_root with container
mdjastrzebski Oct 16, 2024
9e7b1ab
chore: fix *ByType typing
mdjastrzebski Oct 16, 2024
8b8c135
chore: remove irrelevant tests
mdjastrzebski Oct 16, 2024
95030fb
chore: remove redundant string validation feature
mdjastrzebski Oct 16, 2024
12b4f76
refactor: cleanup renderer code
mdjastrzebski Oct 16, 2024
08747ea
chore: migrate act from RTL
mdjastrzebski Oct 16, 2024
8f3bda1
chore: remove test renderer dep
mdjastrzebski Oct 16, 2024
ddc8da7
chore: filter expected errors
mdjastrzebski Oct 16, 2024
cf4b8b7
chore: reduce act warnings
mdjastrzebski Oct 16, 2024
a9b0b44
refactor: renderer API to be more similar to React DOM
mdjastrzebski Oct 17, 2024
1fb7552
chore: simplify find-all
mdjastrzebski Oct 17, 2024
2d434d7
Merge branch 'main' into poc/custom-renderer
mdjastrzebski Oct 18, 2024
12abbe0
chore: create yarn lock
mdjastrzebski Oct 18, 2024
db18123
refactor: tweaks
mdjastrzebski Oct 18, 2024
e0d6c21
refactor: fix test
mdjastrzebski Oct 18, 2024
2c70f9d
refactor: constants
mdjastrzebski Oct 18, 2024
b1282e6
chore: tweak setup
mdjastrzebski Oct 18, 2024
85442c4
refactor: exclude hidden elements
mdjastrzebski Oct 19, 2024
d15b6e9
chore: reformat comments
mdjastrzebski Oct 21, 2024
ab06cf5
refactor: self code review
mdjastrzebski Oct 21, 2024
8e521ff
refactor: migrate to universal-text-renderer
mdjastrzebski Nov 3, 2024
7280311
Merge branch 'main' into poc/custom-renderer
mdjastrzebski Nov 3, 2024
a94fb90
refactor: update UTR 0.2.0
mdjastrzebski Nov 3, 2024
81b73f1
chore: use RN renderer from universal-test-renderer
mdjastrzebski Nov 8, 2024
073b8aa
chore: remove concurrentRoot option
mdjastrzebski Nov 13, 2024
8610930
chore: fix typecheck
mdjastrzebski Nov 13, 2024
e78659b
Merge branch 'poc/custom-renderer' into v14
mdjastrzebski Nov 13, 2024
9e6d34c
chore: fix lint
mdjastrzebski Nov 13, 2024
f5b27c2
refactor: clean up
mdjastrzebski Nov 13, 2024
e11afa3
refactor: remove unsafe queries (#1706)
mdjastrzebski Nov 13, 2024
b3efc9b
refactor: improve code coverage, remove dead code
mdjastrzebski Nov 13, 2024
8353491
chore: improve test coverage
mdjastrzebski Nov 13, 2024
adb1e69
chore: ⬆️ codecov
mdjastrzebski Nov 13, 2024
1e5ee4b
chore: release:alpha script
mdjastrzebski Nov 20, 2024
a6ced5e
chore: version
mdjastrzebski Nov 20, 2024
e905792
chore: release v14.0.0-alpha.0
mdjastrzebski Nov 20, 2024
afe3142
Merge branch 'main' into v14
mdjastrzebski Mar 8, 2025
3db7728
order imports
mdjastrzebski Mar 8, 2025
34b1915
fix
mdjastrzebski Mar 8, 2025
38058e9
.
mdjastrzebski Mar 8, 2025
40ed1a9
refactor: update to universal-test-renderer@0.6.0
mdjastrzebski Mar 10, 2025
745696b
.
mdjastrzebski Mar 10, 2025
11ff2bb
chore: release v14.0.0-alpha.1
mdjastrzebski Mar 10, 2025
97bc3e9
update UTR to 0.7.0
mdjastrzebski Dec 30, 2025
c5a2f3e
wip
mdjastrzebski Dec 31, 2025
6431b95
classic fire event simulation using fibers
mdjastrzebski Jan 1, 2026
e4e8686
tweaks
mdjastrzebski Jan 1, 2026
9bc7098
update UTR to 0.9.0
mdjastrzebski Jan 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ coverage:
target: 80% # Required patch coverage target
project:
default:
threshold: 0.5% # Allowable coverage drop in percentage points
threshold: 0.5% # Allowable coverage drop in percentage points

comment:
behavior: default
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,3 @@ jobs:
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

test-react-18:
needs: [install-cache-deps]
runs-on: ubuntu-latest
name: Test React 18
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js and deps
uses: ./.github/actions/setup-deps

- name: Switch to React 18
run: |
yarn remove react react-test-renderer react-native @react-native/babel-preset
yarn add -D react@18.3.1 react-test-renderer@18.3.1 react-native@0.77.0 @react-native/babel-preset@0.77.0

- name: Test
run: yarn test:ci
2 changes: 1 addition & 1 deletion examples/cookbook/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"rules": {
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": "off",
"react-native/no-color-literals": "off",
"react-native-a11y/has-valid-accessibility-descriptors": "off",
"react-native-a11y/has-valid-accessibility-descriptors": "off"
}
}
6 changes: 5 additions & 1 deletion examples/cookbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</p>

# React Native Testing Library Cookbook App

Welcome to the React Native Testing Library (RNTL) Cookbook! This app is designed to provide developers with a collection of best practices, ready-made recipes, and tips & tricks to help you effectively test your React Native applications. Whether you’re just starting out with testing or looking to deepen your skills, this cookbook offers something for everyone.

Each recipe described in the Cookbook should have a corresponding code example screen in this repo.
Expand All @@ -12,19 +13,22 @@ Since examples will showcase usage of different dependencies, the dependencies i
file will grow much larger that in a normal React Native. This is fine 🐶☕️🔥.

## Running the App

1. Clone the repo `git clone git@github.com:callstack/react-native-testing-library.git`
2. Go to the `examples/cookbook` directory `cd examples/cookbook`
3. Install dependencies `yarn`
4. Run the app `yarn start`
5. Run the app either on iOS or Android by clicking on `i` or `a` in the terminal.

## How to Contribute

We invite all developers, from beginners to experts, to contribute your own recipes! If you have a clever solution, best practice, or useful tip, we encourage you to:

1. Submit a Pull Request with your recipe.
2. Join the conversation on GitHub [here](https://github.com/callstack/react-native-testing-library/issues/1624) to discuss ideas, ask questions, or provide feedback.

## Screenshots From the App

| Home Screen | Phonebook with Net. Req. Example |
|-------------------------------------------------------|-----------------------------------------------------------------|
| ----------------------------------------------------- | --------------------------------------------------------------- |
| ![home-screenshot](assets/readme/home-screenshot.png) | ![phonebook-screenshot](assets/readme/phonebook-screenshot.png) |
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User } from '../types';
import {http, HttpResponse} from "msw";
import {setupServer} from "msw/node";
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

// Define request handlers and response resolvers for random user API.
// By default, we always return the happy path response.
Expand Down
108 changes: 28 additions & 80 deletions flow-typed/npm/jest_v26.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
* that come from itself -- the only difference is that the implementation
* will also be executed when the mock is called.
*/
mockImplementation(
fn: (...args: TArguments) => TReturn
): JestMockFn<TArguments, TReturn>,
mockImplementation(fn: (...args: TArguments) => TReturn): JestMockFn<TArguments, TReturn>,
/**
* Accepts a function that will be used as an implementation of the mock for
* one call to the mocked function. Can be chained so that multiple function
* calls produce different results.
*/
mockImplementationOnce(
fn: (...args: TArguments) => TReturn
): JestMockFn<TArguments, TReturn>,
mockImplementationOnce(fn: (...args: TArguments) => TReturn): JestMockFn<TArguments, TReturn>,
/**
* Accepts a string to use in test result output in place of "jest.fn()" to
* indicate which mock function is being referenced.
Expand All @@ -89,9 +85,7 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
/**
* Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value))
*/
mockResolvedValueOnce(
value: TReturn
): JestMockFn<TArguments, Promise<TReturn>>,
mockResolvedValueOnce(value: TReturn): JestMockFn<TArguments, Promise<TReturn>>,
/**
* Sugar for jest.fn().mockImplementation(() => Promise.reject(value))
*/
Expand Down Expand Up @@ -182,7 +176,7 @@ type JestStyledComponentsMatchersType = {
toHaveStyleRule(
property: string,
value: JestStyledComponentsMatcherValue,
options?: JestStyledComponentsMatcherOptions
options?: JestStyledComponentsMatcherOptions,
): void,
...
};
Expand All @@ -205,20 +199,17 @@ type EnzymeMatchersType = {
toExist(): void,
toHaveClassName(className: string): void,
toHaveHTML(html: string): void,
toHaveProp: ((propKey: string, propValue?: any) => void) &
((props: { ... }) => void),
toHaveProp: ((propKey: string, propValue?: any) => void) & ((props: { ... }) => void),
toHaveRef(refName: string): void,
toHaveState: ((stateKey: string, stateValue?: any) => void) &
((state: { ... }) => void),
toHaveStyle: ((styleKey: string, styleValue?: any) => void) &
((style: { ... }) => void),
toHaveState: ((stateKey: string, stateValue?: any) => void) & ((state: { ... }) => void),
toHaveStyle: ((styleKey: string, styleValue?: any) => void) & ((style: { ... }) => void),
toHaveTagName(tagName: string): void,
toHaveText(text: string): void,
toHaveValue(value: any): void,
toIncludeText(text: string): void,
toMatchElement(
element: React$Element<any>,
options?: {| ignoreProps?: boolean, verbose?: boolean |}
options?: {| ignoreProps?: boolean, verbose?: boolean |},
): void,
toMatchSelector(selector: string): void,
// 7.x
Expand Down Expand Up @@ -250,10 +241,7 @@ type DomTestingLibraryType = {
toHaveFocus(): void,
toHaveFormValues(expectedValues: { [name: string]: any, ... }): void,
toHaveStyle(css: string | { [name: string]: any, ... }): void,
toHaveTextContent(
text: string | RegExp,
options?: {| normalizeWhitespace: boolean |}
): void,
toHaveTextContent(text: string | RegExp, options?: {| normalizeWhitespace: boolean |}): void,
toHaveValue(value?: string | string[] | number): void,

// 5.x
Expand Down Expand Up @@ -562,7 +550,7 @@ type SnapshotDiffType = {
aAnnotation?: string,
bAnnotation?: string,
|},
testName?: string
testName?: string,
): void,
...
};
Expand Down Expand Up @@ -816,7 +804,7 @@ type JestObjectType = {
* implementation.
*/
fn<TArguments: $ReadOnlyArray<*>, TReturn>(
implementation?: (...args: TArguments) => TReturn
implementation?: (...args: TArguments) => TReturn,
): JestMockFn<TArguments, TReturn>,
/**
* Determines if the given function is a mocked function.
Expand All @@ -836,11 +824,7 @@ type JestObjectType = {
* The third argument can be used to create virtual mocks -- mocks of modules
* that don't exist anywhere in the system.
*/
mock(
moduleName: string,
moduleFactory?: any,
options?: Object
): JestObjectType,
mock(moduleName: string, moduleFactory?: any, options?: Object): JestObjectType,
/**
* Returns the actual module instead of a mock, bypassing all checks on
* whether the module should receive a mock implementation or not.
Expand Down Expand Up @@ -920,11 +904,7 @@ type JestObjectType = {
* Creates a mock function similar to jest.fn but also tracks calls to
* object[methodName].
*/
spyOn(
object: Object,
methodName: string,
accessType?: 'get' | 'set'
): JestMockFn<any, any>,
spyOn(object: Object, methodName: string, accessType?: 'get' | 'set'): JestMockFn<any, any>,
/**
* Set the default timeout interval for tests and before/after hooks in milliseconds.
* Note: The default timeout interval is 5 seconds if this method is not called.
Expand All @@ -941,25 +921,13 @@ type JestDoneFn = {|
|};

/** Runs this function after every test inside this context */
declare function afterEach(
fn: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void;
declare function afterEach(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
/** Runs this function before every test inside this context */
declare function beforeEach(
fn: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void;
declare function beforeEach(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
/** Runs this function after all tests have finished inside this context */
declare function afterAll(
fn: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void;
declare function afterAll(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
/** Runs this function before any tests have started inside this context */
declare function beforeAll(
fn: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void;
declare function beforeAll(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;

/** A context for grouping tests together */
declare var describe: {
Expand All @@ -982,11 +950,7 @@ declare var describe: {
*/
each(
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>,
timeout?: number
) => void,
): (name: JestTestName, fn?: (...args: Array<any>) => ?Promise<mixed>, timeout?: number) => void,
...
};

Expand All @@ -999,11 +963,7 @@ declare var it: {
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
(
name: JestTestName,
fn?: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void,
(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
/**
* Only run this test
*
Expand All @@ -1012,17 +972,13 @@ declare var it: {
* @param {number} Timeout for the test, in milliseconds.
*/
only: {|
(
name: JestTestName,
fn?: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void,
(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
each(
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>,
timeout?: number
timeout?: number,
) => void,
|},
/**
Expand All @@ -1032,11 +988,7 @@ declare var it: {
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
skip(
name: JestTestName,
fn?: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
): void,
skip(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
/**
* Highlight planned tests in the summary output
*
Expand All @@ -1053,7 +1005,7 @@ declare var it: {
concurrent(
name: JestTestName,
fn?: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
timeout?: number,
): void,
/**
* each runs this test against array of argument arrays per each run
Expand All @@ -1062,18 +1014,14 @@ declare var it: {
*/
each(
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>,
timeout?: number
) => void,
): (name: JestTestName, fn?: (...args: Array<any>) => ?Promise<mixed>, timeout?: number) => void,
...
};

declare function fit(
name: JestTestName,
fn: (done: JestDoneFn) => ?Promise<mixed>,
timeout?: number
timeout?: number,
): void;
/** An individual test unit */
declare var test: typeof it;
Expand Down Expand Up @@ -1146,7 +1094,7 @@ type JestPrettyFormatPlugin = {
serialize: JestPrettyFormatPrint,
indent: JestPrettyFormatIndent,
opts: JestPrettyFormatOptions,
colors: JestPrettyFormatColors
colors: JestPrettyFormatColors,
) => string,
test: (any) => boolean,
...
Expand All @@ -1158,7 +1106,7 @@ type JestPrettyFormatPlugins = Array<JestPrettyFormatPlugin>;
declare var expect: {
/** The object that you want to make assertions against */
(
value: any
value: any,
): JestExpectType &
JestPromiseType &
EnzymeMatchersType &
Expand Down Expand Up @@ -1210,7 +1158,7 @@ declare var jasmine: {
createSpy(name: string): JestSpyType,
createSpyObj(
baseName: string,
methodNames: Array<string>
methodNames: Array<string>,
): { [methodName: string]: JestSpyType, ... },
objectContaining(value: Object): Object,
stringMatching(value: string): string,
Expand Down
11 changes: 4 additions & 7 deletions flow-typed/npm/react-test-renderer_v16.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ type ReactTestInstance = {

findAll(
predicate: (node: ReactTestInstance) => boolean,
options?: { deep: boolean }
): ReactTestInstance[],
findAllByType(
type: React$ElementType,
options?: { deep: boolean }
options?: { deep: boolean },
): ReactTestInstance[],
findAllByType(type: React$ElementType, options?: { deep: boolean }): ReactTestInstance[],
findAllByProps(
props: { [propName: string]: any },
options?: { deep: boolean }
options?: { deep: boolean },
): ReactTestInstance[],
};

Expand All @@ -63,7 +60,7 @@ declare module 'react-test-renderer' {

declare function create(
nextElement: React$Element<any>,
options?: TestRendererOptions
options?: TestRendererOptions,
): ReactTestRenderer;

declare function act(callback: () => void): Thenable;
Expand Down
5 changes: 1 addition & 4 deletions jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { resetToDefaults, configure } from './src/pure';
import { resetToDefaults } from './src/pure';

beforeEach(() => {
resetToDefaults();
if (process.env.CONCURRENT_MODE === '0') {
configure({ concurrentRoot: false });
}
});
Loading