Skip to content

Commit 043f51d

Browse files
feat(breaking): remove legacy debug export (#328)
* Removed global `debug` functions * Removed global `debug` from docs * Cleanup * Added migration section Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent b3e5ca3 commit 043f51d

File tree

8 files changed

+5
-272
lines changed

8 files changed

+5
-272
lines changed

src/__tests__/__snapshots__/debug.test.js.snap

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/__tests__/debug.test.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/debug.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow
22
import act from './act';
33
import cleanup from './cleanup';
4-
import debug from './debug';
54
import fireEvent from './fireEvent';
65
import flushMicrotasksQueue from './flushMicrotasksQueue';
76
import render from './render';
@@ -11,7 +10,6 @@ import within from './within';
1110

1211
export { act };
1312
export { cleanup };
14-
export { debug };
1513
export { fireEvent };
1614
export { flushMicrotasksQueue };
1715
export { render };

typings/__tests__/index.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
fireEvent,
77
shallow,
88
flushMicrotasksQueue,
9-
debug,
109
waitForElement,
1110
act,
1211
within,
@@ -251,17 +250,6 @@ const shallowTree: { output: React.ReactElement<any> } = shallow(
251250

252251
const waitForFlush: Promise<any> = flushMicrotasksQueue();
253252

254-
// debug API
255-
debug(<TestComponent />);
256-
debug(<TestComponent />, 'message');
257-
debug(getByNameString);
258-
debug(getByNameString, 'message');
259-
debug.shallow(<TestComponent />);
260-
debug.shallow(<TestComponent />, 'message');
261-
debug.deep(<TestComponent />);
262-
debug.deep(<TestComponent />, 'message');
263-
debug.deep(tree.toJSON());
264-
265253
const waitBy: Promise<ReactTestInstance> = waitForElement<ReactTestInstance>(
266254
() => tree.getByName('View')
267255
);

typings/index.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,6 @@ export type WaitForElementFunction = <T = any>(
230230
interval?: number
231231
) => Promise<T>;
232232

233-
export type DebugFunction = (
234-
instance: ReactTestInstance | React.ReactElement<any>,
235-
message?: string
236-
) => void;
237-
238-
export type DebugAPI = DebugFunction & {
239-
shallow: DebugFunction;
240-
deep: (
241-
instance: React.ReactElement<any> | ReactTestRendererJSON | null,
242-
message?: string
243-
) => void;
244-
};
245-
246233
export declare const render: (
247234
component: React.ReactElement<any>,
248235
options?: RenderOptions
@@ -252,7 +239,6 @@ export declare const shallow: <P = {}>(
252239
) => { output: React.ReactElement<P> };
253240
export declare const flushMicrotasksQueue: () => Promise<any>;
254241
export declare const cleanup: () => void;
255-
export declare const debug: DebugAPI;
256242
export declare const fireEvent: FireEventAPI;
257243
export declare const waitForElement: WaitForElementFunction;
258244
export declare const act: (callback: () => void) => Thenable;

website/docs/API.md

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -370,63 +370,6 @@ Use cases for scoped queries include:
370370
- queries scoped to a single item inside a FlatList containing many items
371371
- queries scoped to a single screen in tests involving screen transitions (e.g. with react-navigation)
372372

373-
## `debug`
374-
375-
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/debug.test.js)
376-
377-
Log prettified shallowly rendered component or test instance (just like snapshot) to stdout.
378-
379-
```jsx
380-
import { debug } from 'react-native-testing-library';
381-
382-
debug(<Component />);
383-
debug.shallow(<Component />); // an alias for `debug`
384-
```
385-
386-
logs:
387-
388-
```jsx
389-
<TouchableOpacity
390-
activeOpacity={0.2}
391-
onPress={[Function bound fn]}
392-
>
393-
<TextComponent
394-
text="Press me"
395-
/>
396-
</TouchableOpacity>
397-
```
398-
399-
There's also `debug.deep` that renders deeply to stdout.
400-
401-
```jsx
402-
import { debug } from 'react-native-testing-library';
403-
404-
debug.deep(<Component />);
405-
debug.deep(toJSON(), 'actually debug JSON too'); // useful when Component state changes
406-
```
407-
408-
logs:
409-
410-
```jsx
411-
<View
412-
accessible={true}
413-
isTVSelectable={true}
414-
onResponderGrant={[Function bound touchableHandleResponderGrant]}
415-
// ... more props
416-
style={
417-
Object {
418-
\\"opacity\\": 1,
419-
}
420-
}
421-
>
422-
<Text>
423-
Press me
424-
</Text>
425-
</View>
426-
```
427-
428-
Optionally you can provide a string message as a second argument to `debug`, which will be displayed right after the component.
429-
430373
## `flushMicrotasksQueue`
431374

432375
Waits for microtasks queue to flush. Useful if you want to wait for some promises with `async/await`.

website/docs/Migration20.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ title: Migration to 2.0
55

66
This guides describes major steps involved in migrating your testing code from using React Native Testing Library version `1.x` to version `2.0`.
77

8+
9+
## Removed global `debug` function
10+
11+
Global debug function has been removed in favor of `debug()` method returned from `render()` function.
12+
813
## Some `byTestId` queries behavior changes
914

1015
In version `1.x` `getByTestId` and `queryByTestId` could return non-native elements in tests. This was in contrast with other query functions: `getAllByTestId`, `queryAllByTestId`, `findByTestId` and `findAllByTestId` which returned only elements that would be rendered to native components (e.g. `View`, `Text`, etc).

0 commit comments

Comments
 (0)