Skip to content

Commit c5a2f3e

Browse files
committed
wip
1 parent 97bc3e9 commit c5a2f3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+900
-844
lines changed

examples/cookbook/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"rules": {
44
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": "off",
55
"react-native/no-color-literals": "off",
6-
"react-native-a11y/has-valid-accessibility-descriptors": "off",
6+
"react-native-a11y/has-valid-accessibility-descriptors": "off"
77
}
88
}

examples/cookbook/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
</p>
44

55
# React Native Testing Library Cookbook App
6+
67
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.
78

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

1415
## Running the App
16+
1517
1. Clone the repo `git clone [email protected]:callstack/react-native-testing-library.git`
1618
2. Go to the `examples/cookbook` directory `cd examples/cookbook`
1719
3. Install dependencies `yarn`
1820
4. Run the app `yarn start`
1921
5. Run the app either on iOS or Android by clicking on `i` or `a` in the terminal.
2022

2123
## How to Contribute
24+
2225
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:
2326

2427
1. Submit a Pull Request with your recipe.
2528
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.
2629

2730
## Screenshots From the App
31+
2832
| Home Screen | Phonebook with Net. Req. Example |
29-
|-------------------------------------------------------|-----------------------------------------------------------------|
33+
| ----------------------------------------------------- | --------------------------------------------------------------- |
3034
| ![home-screenshot](assets/readme/home-screenshot.png) | ![phonebook-screenshot](assets/readme/phonebook-screenshot.png) |

examples/cookbook/app/network-requests/__tests__/test-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { User } from '../types';
2-
import {http, HttpResponse} from "msw";
3-
import {setupServer} from "msw/node";
2+
import { http, HttpResponse } from 'msw';
3+
import { setupServer } from 'msw/node';
44

55
// Define request handlers and response resolvers for random user API.
66
// By default, we always return the happy path response.

flow-typed/npm/jest_v26.x.x.js

Lines changed: 28 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,13 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
5454
* that come from itself -- the only difference is that the implementation
5555
* will also be executed when the mock is called.
5656
*/
57-
mockImplementation(
58-
fn: (...args: TArguments) => TReturn
59-
): JestMockFn<TArguments, TReturn>,
57+
mockImplementation(fn: (...args: TArguments) => TReturn): JestMockFn<TArguments, TReturn>,
6058
/**
6159
* Accepts a function that will be used as an implementation of the mock for
6260
* one call to the mocked function. Can be chained so that multiple function
6361
* calls produce different results.
6462
*/
65-
mockImplementationOnce(
66-
fn: (...args: TArguments) => TReturn
67-
): JestMockFn<TArguments, TReturn>,
63+
mockImplementationOnce(fn: (...args: TArguments) => TReturn): JestMockFn<TArguments, TReturn>,
6864
/**
6965
* Accepts a string to use in test result output in place of "jest.fn()" to
7066
* indicate which mock function is being referenced.
@@ -89,9 +85,7 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
8985
/**
9086
* Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value))
9187
*/
92-
mockResolvedValueOnce(
93-
value: TReturn
94-
): JestMockFn<TArguments, Promise<TReturn>>,
88+
mockResolvedValueOnce(value: TReturn): JestMockFn<TArguments, Promise<TReturn>>,
9589
/**
9690
* Sugar for jest.fn().mockImplementation(() => Promise.reject(value))
9791
*/
@@ -182,7 +176,7 @@ type JestStyledComponentsMatchersType = {
182176
toHaveStyleRule(
183177
property: string,
184178
value: JestStyledComponentsMatcherValue,
185-
options?: JestStyledComponentsMatcherOptions
179+
options?: JestStyledComponentsMatcherOptions,
186180
): void,
187181
...
188182
};
@@ -205,20 +199,17 @@ type EnzymeMatchersType = {
205199
toExist(): void,
206200
toHaveClassName(className: string): void,
207201
toHaveHTML(html: string): void,
208-
toHaveProp: ((propKey: string, propValue?: any) => void) &
209-
((props: { ... }) => void),
202+
toHaveProp: ((propKey: string, propValue?: any) => void) & ((props: { ... }) => void),
210203
toHaveRef(refName: string): void,
211-
toHaveState: ((stateKey: string, stateValue?: any) => void) &
212-
((state: { ... }) => void),
213-
toHaveStyle: ((styleKey: string, styleValue?: any) => void) &
214-
((style: { ... }) => void),
204+
toHaveState: ((stateKey: string, stateValue?: any) => void) & ((state: { ... }) => void),
205+
toHaveStyle: ((styleKey: string, styleValue?: any) => void) & ((style: { ... }) => void),
215206
toHaveTagName(tagName: string): void,
216207
toHaveText(text: string): void,
217208
toHaveValue(value: any): void,
218209
toIncludeText(text: string): void,
219210
toMatchElement(
220211
element: React$Element<any>,
221-
options?: {| ignoreProps?: boolean, verbose?: boolean |}
212+
options?: {| ignoreProps?: boolean, verbose?: boolean |},
222213
): void,
223214
toMatchSelector(selector: string): void,
224215
// 7.x
@@ -250,10 +241,7 @@ type DomTestingLibraryType = {
250241
toHaveFocus(): void,
251242
toHaveFormValues(expectedValues: { [name: string]: any, ... }): void,
252243
toHaveStyle(css: string | { [name: string]: any, ... }): void,
253-
toHaveTextContent(
254-
text: string | RegExp,
255-
options?: {| normalizeWhitespace: boolean |}
256-
): void,
244+
toHaveTextContent(text: string | RegExp, options?: {| normalizeWhitespace: boolean |}): void,
257245
toHaveValue(value?: string | string[] | number): void,
258246

259247
// 5.x
@@ -562,7 +550,7 @@ type SnapshotDiffType = {
562550
aAnnotation?: string,
563551
bAnnotation?: string,
564552
|},
565-
testName?: string
553+
testName?: string,
566554
): void,
567555
...
568556
};
@@ -816,7 +804,7 @@ type JestObjectType = {
816804
* implementation.
817805
*/
818806
fn<TArguments: $ReadOnlyArray<*>, TReturn>(
819-
implementation?: (...args: TArguments) => TReturn
807+
implementation?: (...args: TArguments) => TReturn,
820808
): JestMockFn<TArguments, TReturn>,
821809
/**
822810
* Determines if the given function is a mocked function.
@@ -836,11 +824,7 @@ type JestObjectType = {
836824
* The third argument can be used to create virtual mocks -- mocks of modules
837825
* that don't exist anywhere in the system.
838826
*/
839-
mock(
840-
moduleName: string,
841-
moduleFactory?: any,
842-
options?: Object
843-
): JestObjectType,
827+
mock(moduleName: string, moduleFactory?: any, options?: Object): JestObjectType,
844828
/**
845829
* Returns the actual module instead of a mock, bypassing all checks on
846830
* whether the module should receive a mock implementation or not.
@@ -920,11 +904,7 @@ type JestObjectType = {
920904
* Creates a mock function similar to jest.fn but also tracks calls to
921905
* object[methodName].
922906
*/
923-
spyOn(
924-
object: Object,
925-
methodName: string,
926-
accessType?: 'get' | 'set'
927-
): JestMockFn<any, any>,
907+
spyOn(object: Object, methodName: string, accessType?: 'get' | 'set'): JestMockFn<any, any>,
928908
/**
929909
* Set the default timeout interval for tests and before/after hooks in milliseconds.
930910
* Note: The default timeout interval is 5 seconds if this method is not called.
@@ -941,25 +921,13 @@ type JestDoneFn = {|
941921
|};
942922

943923
/** Runs this function after every test inside this context */
944-
declare function afterEach(
945-
fn: (done: JestDoneFn) => ?Promise<mixed>,
946-
timeout?: number
947-
): void;
924+
declare function afterEach(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
948925
/** Runs this function before every test inside this context */
949-
declare function beforeEach(
950-
fn: (done: JestDoneFn) => ?Promise<mixed>,
951-
timeout?: number
952-
): void;
926+
declare function beforeEach(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
953927
/** Runs this function after all tests have finished inside this context */
954-
declare function afterAll(
955-
fn: (done: JestDoneFn) => ?Promise<mixed>,
956-
timeout?: number
957-
): void;
928+
declare function afterAll(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
958929
/** Runs this function before any tests have started inside this context */
959-
declare function beforeAll(
960-
fn: (done: JestDoneFn) => ?Promise<mixed>,
961-
timeout?: number
962-
): void;
930+
declare function beforeAll(fn: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void;
963931

964932
/** A context for grouping tests together */
965933
declare var describe: {
@@ -982,11 +950,7 @@ declare var describe: {
982950
*/
983951
each(
984952
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
985-
): (
986-
name: JestTestName,
987-
fn?: (...args: Array<any>) => ?Promise<mixed>,
988-
timeout?: number
989-
) => void,
953+
): (name: JestTestName, fn?: (...args: Array<any>) => ?Promise<mixed>, timeout?: number) => void,
990954
...
991955
};
992956

@@ -999,11 +963,7 @@ declare var it: {
999963
* @param {Function} Test
1000964
* @param {number} Timeout for the test, in milliseconds.
1001965
*/
1002-
(
1003-
name: JestTestName,
1004-
fn?: (done: JestDoneFn) => ?Promise<mixed>,
1005-
timeout?: number
1006-
): void,
966+
(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
1007967
/**
1008968
* Only run this test
1009969
*
@@ -1012,17 +972,13 @@ declare var it: {
1012972
* @param {number} Timeout for the test, in milliseconds.
1013973
*/
1014974
only: {|
1015-
(
1016-
name: JestTestName,
1017-
fn?: (done: JestDoneFn) => ?Promise<mixed>,
1018-
timeout?: number
1019-
): void,
975+
(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
1020976
each(
1021977
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
1022978
): (
1023979
name: JestTestName,
1024980
fn?: (...args: Array<any>) => ?Promise<mixed>,
1025-
timeout?: number
981+
timeout?: number,
1026982
) => void,
1027983
|},
1028984
/**
@@ -1032,11 +988,7 @@ declare var it: {
1032988
* @param {Function} Test
1033989
* @param {number} Timeout for the test, in milliseconds.
1034990
*/
1035-
skip(
1036-
name: JestTestName,
1037-
fn?: (done: JestDoneFn) => ?Promise<mixed>,
1038-
timeout?: number
1039-
): void,
991+
skip(name: JestTestName, fn?: (done: JestDoneFn) => ?Promise<mixed>, timeout?: number): void,
1040992
/**
1041993
* Highlight planned tests in the summary output
1042994
*
@@ -1053,7 +1005,7 @@ declare var it: {
10531005
concurrent(
10541006
name: JestTestName,
10551007
fn?: (done: JestDoneFn) => ?Promise<mixed>,
1056-
timeout?: number
1008+
timeout?: number,
10571009
): void,
10581010
/**
10591011
* each runs this test against array of argument arrays per each run
@@ -1062,18 +1014,14 @@ declare var it: {
10621014
*/
10631015
each(
10641016
...table: Array<Array<mixed> | mixed> | [Array<string>, string]
1065-
): (
1066-
name: JestTestName,
1067-
fn?: (...args: Array<any>) => ?Promise<mixed>,
1068-
timeout?: number
1069-
) => void,
1017+
): (name: JestTestName, fn?: (...args: Array<any>) => ?Promise<mixed>, timeout?: number) => void,
10701018
...
10711019
};
10721020

10731021
declare function fit(
10741022
name: JestTestName,
10751023
fn: (done: JestDoneFn) => ?Promise<mixed>,
1076-
timeout?: number
1024+
timeout?: number,
10771025
): void;
10781026
/** An individual test unit */
10791027
declare var test: typeof it;
@@ -1146,7 +1094,7 @@ type JestPrettyFormatPlugin = {
11461094
serialize: JestPrettyFormatPrint,
11471095
indent: JestPrettyFormatIndent,
11481096
opts: JestPrettyFormatOptions,
1149-
colors: JestPrettyFormatColors
1097+
colors: JestPrettyFormatColors,
11501098
) => string,
11511099
test: (any) => boolean,
11521100
...
@@ -1158,7 +1106,7 @@ type JestPrettyFormatPlugins = Array<JestPrettyFormatPlugin>;
11581106
declare var expect: {
11591107
/** The object that you want to make assertions against */
11601108
(
1161-
value: any
1109+
value: any,
11621110
): JestExpectType &
11631111
JestPromiseType &
11641112
EnzymeMatchersType &
@@ -1210,7 +1158,7 @@ declare var jasmine: {
12101158
createSpy(name: string): JestSpyType,
12111159
createSpyObj(
12121160
baseName: string,
1213-
methodNames: Array<string>
1161+
methodNames: Array<string>,
12141162
): { [methodName: string]: JestSpyType, ... },
12151163
objectContaining(value: Object): Object,
12161164
stringMatching(value: string): string,

flow-typed/npm/react-test-renderer_v16.x.x.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ type ReactTestInstance = {
3131

3232
findAll(
3333
predicate: (node: ReactTestInstance) => boolean,
34-
options?: { deep: boolean }
35-
): ReactTestInstance[],
36-
findAllByType(
37-
type: React$ElementType,
38-
options?: { deep: boolean }
34+
options?: { deep: boolean },
3935
): ReactTestInstance[],
36+
findAllByType(type: React$ElementType, options?: { deep: boolean }): ReactTestInstance[],
4037
findAllByProps(
4138
props: { [propName: string]: any },
42-
options?: { deep: boolean }
39+
options?: { deep: boolean },
4340
): ReactTestInstance[],
4441
};
4542

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

6461
declare function create(
6562
nextElement: React$Element<any>,
66-
options?: TestRendererOptions
63+
options?: TestRendererOptions,
6764
): ReactTestRenderer;
6865

6966
declare function act(callback: () => void): Thenable;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"release-it": "^18.0.0",
9494
"typescript": "^5.6.3",
9595
"typescript-eslint": "^8.19.1",
96-
"universal-test-renderer": "0.7.0"
96+
"universal-test-renderer": "0.8.1"
9797
},
9898
"publishConfig": {
9999
"registry": "https://registry.npmjs.org"

0 commit comments

Comments
 (0)