Skip to content

feat(breaking): remove legacy debug export #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 0 additions & 57 deletions src/__tests__/__snapshots__/debug.test.js.snap

This file was deleted.

88 changes: 0 additions & 88 deletions src/__tests__/debug.test.js

This file was deleted.

42 changes: 0 additions & 42 deletions src/debug.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow
import act from './act';
import cleanup from './cleanup';
import debug from './debug';
import fireEvent from './fireEvent';
import flushMicrotasksQueue from './flushMicrotasksQueue';
import render from './render';
Expand All @@ -11,7 +10,6 @@ import within from './within';

export { act };
export { cleanup };
export { debug };
export { fireEvent };
export { flushMicrotasksQueue };
export { render };
Expand Down
12 changes: 0 additions & 12 deletions typings/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
fireEvent,
shallow,
flushMicrotasksQueue,
debug,
waitForElement,
act,
within,
Expand Down Expand Up @@ -251,17 +250,6 @@ const shallowTree: { output: React.ReactElement<any> } = shallow(

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

// debug API
debug(<TestComponent />);
debug(<TestComponent />, 'message');
debug(getByNameString);
debug(getByNameString, 'message');
debug.shallow(<TestComponent />);
debug.shallow(<TestComponent />, 'message');
debug.deep(<TestComponent />);
debug.deep(<TestComponent />, 'message');
debug.deep(tree.toJSON());

const waitBy: Promise<ReactTestInstance> = waitForElement<ReactTestInstance>(
() => tree.getByName('View')
);
Expand Down
14 changes: 0 additions & 14 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,6 @@ export type WaitForElementFunction = <T = any>(
interval?: number
) => Promise<T>;

export type DebugFunction = (
instance: ReactTestInstance | React.ReactElement<any>,
message?: string
) => void;

export type DebugAPI = DebugFunction & {
shallow: DebugFunction;
deep: (
instance: React.ReactElement<any> | ReactTestRendererJSON | null,
message?: string
) => void;
};

export declare const render: (
component: React.ReactElement<any>,
options?: RenderOptions
Expand All @@ -252,7 +239,6 @@ export declare const shallow: <P = {}>(
) => { output: React.ReactElement<P> };
export declare const flushMicrotasksQueue: () => Promise<any>;
export declare const cleanup: () => void;
export declare const debug: DebugAPI;
export declare const fireEvent: FireEventAPI;
export declare const waitForElement: WaitForElementFunction;
export declare const act: (callback: () => void) => Thenable;
Expand Down
57 changes: 0 additions & 57 deletions website/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,63 +370,6 @@ Use cases for scoped queries include:
- queries scoped to a single item inside a FlatList containing many items
- queries scoped to a single screen in tests involving screen transitions (e.g. with react-navigation)

## `debug`

- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/debug.test.js)

Log prettified shallowly rendered component or test instance (just like snapshot) to stdout.

```jsx
import { debug } from 'react-native-testing-library';

debug(<Component />);
debug.shallow(<Component />); // an alias for `debug`
```

logs:

```jsx
<TouchableOpacity
activeOpacity={0.2}
onPress={[Function bound fn]}
>
<TextComponent
text="Press me"
/>
</TouchableOpacity>
```

There's also `debug.deep` that renders deeply to stdout.

```jsx
import { debug } from 'react-native-testing-library';

debug.deep(<Component />);
debug.deep(toJSON(), 'actually debug JSON too'); // useful when Component state changes
```

logs:

```jsx
<View
accessible={true}
isTVSelectable={true}
onResponderGrant={[Function bound touchableHandleResponderGrant]}
// ... more props
style={
Object {
\\"opacity\\": 1,
}
}
>
<Text>
Press me
</Text>
</View>
```

Optionally you can provide a string message as a second argument to `debug`, which will be displayed right after the component.

## `flushMicrotasksQueue`

Waits for microtasks queue to flush. Useful if you want to wait for some promises with `async/await`.
Expand Down
5 changes: 5 additions & 0 deletions website/docs/Migration20.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ title: Migration to 2.0

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


## Removed global `debug` function

Global debug function has been removed in favor of `debug()` method returned from `render()` function.

## Some `byTestId` queries behavior changes

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).
Expand Down