Skip to content

Commit

Permalink
[v13] chore: remove debug shallow (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed May 8, 2024
1 parent 05f9804 commit 1ddef7f
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 166 deletions.
100 changes: 0 additions & 100 deletions src/__tests__/__snapshots__/render-debug.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -367,106 +367,6 @@ exports[`debug: another custom message 1`] = `
</View>"
`;

exports[`debug: shallow 1`] = `
"<View>
<Text>
Is the banana fresh?
</Text>
<Text
testID="bananaFresh"
>
not fresh
</Text>
<TextInput
placeholder="Add custom freshness"
testID="bananaCustomFreshness"
value="Custom Freshie"
/>
<TextInput
defaultValue="What did you inspect?"
placeholder="Who inspected freshness?"
testID="bananaChef"
value="I inspected freshie"
/>
<TextInput
defaultValue="What banana?"
/>
<TextInput
defaultValue="hello"
value=""
/>
<MyButton
onPress={[Function changeFresh]}
>
Change freshness!
</MyButton>
<Text
testID="duplicateText"
>
First Text
</Text>
<Text
testID="duplicateText"
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

exports[`debug: shallow with message 1`] = `
"my other custom message
<View>
<Text>
Is the banana fresh?
</Text>
<Text
testID="bananaFresh"
>
not fresh
</Text>
<TextInput
placeholder="Add custom freshness"
testID="bananaCustomFreshness"
value="Custom Freshie"
/>
<TextInput
defaultValue="What did you inspect?"
placeholder="Who inspected freshness?"
testID="bananaChef"
value="I inspected freshie"
/>
<TextInput
defaultValue="What banana?"
/>
<TextInput
defaultValue="hello"
value=""
/>
<MyButton
onPress={[Function changeFresh]}
>
Change freshness!
</MyButton>
<Text
testID="duplicateText"
>
First Text
</Text>
<Text
testID="duplicateText"
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

exports[`debug: with message 1`] = `
"my custom message
Expand Down
14 changes: 6 additions & 8 deletions src/__tests__/render-debug.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,19 @@ test('debug', () => {

screen.debug();
screen.debug('my custom message');
screen.debug.shallow();
screen.debug.shallow('my other custom message');
screen.debug({ message: 'another custom message' });

const mockCalls = jest.mocked(console.log).mock.calls;
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
expect(stripAnsi(mockCalls[1][0] + mockCalls[1][1])).toMatchSnapshot('with message');
expect(stripAnsi(mockCalls[2][0])).toMatchSnapshot('shallow');
expect(stripAnsi(mockCalls[3][0] + mockCalls[3][1])).toMatchSnapshot('shallow with message');
expect(stripAnsi(mockCalls[4][0] + mockCalls[4][1])).toMatchSnapshot('another custom message');
expect(stripAnsi(mockCalls[2][0] + mockCalls[2][1])).toMatchSnapshot('another custom message');

const mockWarnCalls = jest.mocked(console.warn).mock.calls;
expect(mockWarnCalls[0]).toEqual([
'Using debug("message") is deprecated and will be removed in future release, please use debug({ message; "message" }) instead.',
]);
expect(mockWarnCalls[0]).toMatchInlineSnapshot(`
[
"Using debug("message") is deprecated and will be removed in future release, please use debug({ message: "message" }) instead.",
]
`);
});

test('debug changing component', () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ test('screen throws without render', () => {
expect(() => screen.root).toThrow('`render` method has not been called');
expect(() => screen.UNSAFE_root).toThrow('`render` method has not been called');
expect(() => screen.debug()).toThrow('`render` method has not been called');
expect(() => screen.debug.shallow()).toThrow('`render` method has not been called');
expect(() => screen.getByText('Mt. Everest')).toThrow('`render` method has not been called');
});
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebugOptions } from './helpers/debug-deep';
import { DebugOptions } from './helpers/debug';

/**
* Global configuration options for React Native Testing Library.
Expand Down
22 changes: 0 additions & 22 deletions src/helpers/debug-shallow.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/helpers/debug-deep.ts → src/helpers/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type DebugOptions = {
/**
* Log pretty-printed deep test component instance
*/
export default function debugDeep(
export function debug(
instance: ReactTestRendererJSON | ReactTestRendererJSON[],
options?: DebugOptions | string,
) {
Expand Down
17 changes: 6 additions & 11 deletions src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import act from './act';
import { addToCleanupQueue } from './cleanup';
import { getConfig } from './config';
import { getHostChildren } from './helpers/component-tree';
import debugDeep, { DebugOptions } from './helpers/debug-deep';
import debugShallow from './helpers/debug-shallow';
import { debug, DebugOptions } from './helpers/debug';
import { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';
import { validateStringsRenderedWithinText } from './helpers/string-validation';
import { renderWithAct } from './render-act';
Expand Down Expand Up @@ -105,7 +104,7 @@ function buildRenderResult(
unmount,
rerender: update, // alias for `update`
toJSON: renderer.toJSON,
debug: debug(instance, renderer),
debug: makeDebug(instance, renderer),
get root(): ReactTestInstance {
return getHostChildren(instance)[0];
},
Expand Down Expand Up @@ -139,12 +138,9 @@ function updateWithAct(
};
}

export interface DebugFunction {
(options?: DebugOptions | string): void;
shallow: (message?: string) => void;
}
export type DebugFunction = (options?: DebugOptions | string) => void;

function debug(instance: ReactTestInstance, renderer: ReactTestRenderer): DebugFunction {
function makeDebug(instance: ReactTestInstance, renderer: ReactTestRenderer): DebugFunction {
function debugImpl(options?: DebugOptions | string) {
const { defaultDebugOptions } = getConfig();
const debugOptions =
Expand All @@ -155,15 +151,14 @@ function debug(instance: ReactTestInstance, renderer: ReactTestRenderer): DebugF
if (typeof options === 'string') {
// eslint-disable-next-line no-console
console.warn(
'Using debug("message") is deprecated and will be removed in future release, please use debug({ message; "message" }) instead.',
'Using debug("message") is deprecated and will be removed in future release, please use debug({ message: "message" }) instead.',
);
}

const json = renderer.toJSON();
if (json) {
return debugDeep(json, debugOptions);
return debug(json, debugOptions);
}
}
debugImpl.shallow = (message?: string) => debugShallow(instance, message);
return debugImpl;
}
1 change: 0 additions & 1 deletion src/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const notImplemented = () => {
const notImplementedDebug = () => {
throw new Error(SCREEN_ERROR);
};
notImplementedDebug.shallow = notImplemented;

interface Screen extends RenderResult {
isDetached?: boolean;
Expand Down
18 changes: 0 additions & 18 deletions src/shallow.ts

This file was deleted.

1 change: 0 additions & 1 deletion typings/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ type DebugOptions = {

type Debug = {
(options?: DebugOptions | string): void,
shallow: (message?: string) => void,
};

type Queries = ByTextQueries &
Expand Down
6 changes: 4 additions & 2 deletions website/docs/MigrationV13.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## @@ -0,0 +1,20 @@

id: migration-v13
title: Migration to 13.0

Expand Down Expand Up @@ -62,6 +60,10 @@ const view = screen.getBy*(...); // Find the element using any query: *ByRole, *
expect(view).toHaveAccessibilityValue({ now: 50, min: 0, max: 50 }); // Assert its accessibility value
```

## Removed `debug.shallow`

For a time being we didn't support shallow rendering. Now we are removing the last remains of it: `debug.shallow()`. If you are interested in shallow rendering see [here](migration-v2#removed-global-shallow-function).

# Other changes

## Updated `flushMicroTasks` internal method
Expand Down

0 comments on commit 1ddef7f

Please sign in to comment.