Skip to content

Commit 0fa06db

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 3ad21b3 commit 0fa06db

File tree

8 files changed

+4
-272
lines changed

8 files changed

+4
-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
waitFor,
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> = waitFor<ReactTestInstance>(() =>
266254
tree.getByName('View')
267255
);

typings/index.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,6 @@ export type WaitForFunction = <T = any>(
234234
options?: WaitForOptions
235235
) => Promise<T>;
236236

237-
export type DebugFunction = (
238-
instance: ReactTestInstance | React.ReactElement<any>,
239-
message?: string
240-
) => void;
241-
242-
export type DebugAPI = DebugFunction & {
243-
shallow: DebugFunction;
244-
deep: (
245-
instance: React.ReactElement<any> | ReactTestRendererJSON | null,
246-
message?: string
247-
) => void;
248-
};
249-
250237
export declare const render: (
251238
component: React.ReactElement<any>,
252239
options?: RenderOptions
@@ -256,7 +243,6 @@ export declare const shallow: <P = {}>(
256243
) => { output: React.ReactElement<P> };
257244
export declare const flushMicrotasksQueue: () => Promise<any>;
258245
export declare const cleanup: () => void;
259-
export declare const debug: DebugAPI;
260246
export declare const fireEvent: FireEventAPI;
261247
export declare const waitFor: WaitForFunction;
262248
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
@@ -369,63 +369,6 @@ Use cases for scoped queries include:
369369
- queries scoped to a single item inside a FlatList containing many items
370370
- queries scoped to a single screen in tests involving screen transitions (e.g. with react-navigation)
371371

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

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

website/docs/Migration20.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Both changes should improve code readibility.
3535
Please note that in many cases `waitFor` call can be replaced by proper use of `findBy` asynchonous queries resulting in more streamlined test code.
3636
:::
3737
38+
## Removed global `debug` function
39+
40+
Global debug function has been removed in favor of `debug()` method returned from `render()` function.
41+
3842
## Some `byTestId` queries behavior changes
3943
4044
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)