Skip to content

Commit 1ddef7f

Browse files
[v13] chore: remove debug shallow (#1601)
1 parent 05f9804 commit 1ddef7f

File tree

11 files changed

+18
-166
lines changed

11 files changed

+18
-166
lines changed

src/__tests__/__snapshots__/render-debug.test.tsx.snap

-100
Original file line numberDiff line numberDiff line change
@@ -367,106 +367,6 @@ exports[`debug: another custom message 1`] = `
367367
</View>"
368368
`;
369369

370-
exports[`debug: shallow 1`] = `
371-
"<View>
372-
<Text>
373-
Is the banana fresh?
374-
</Text>
375-
<Text
376-
testID="bananaFresh"
377-
>
378-
not fresh
379-
</Text>
380-
<TextInput
381-
placeholder="Add custom freshness"
382-
testID="bananaCustomFreshness"
383-
value="Custom Freshie"
384-
/>
385-
<TextInput
386-
defaultValue="What did you inspect?"
387-
placeholder="Who inspected freshness?"
388-
testID="bananaChef"
389-
value="I inspected freshie"
390-
/>
391-
<TextInput
392-
defaultValue="What banana?"
393-
/>
394-
<TextInput
395-
defaultValue="hello"
396-
value=""
397-
/>
398-
<MyButton
399-
onPress={[Function changeFresh]}
400-
>
401-
Change freshness!
402-
</MyButton>
403-
<Text
404-
testID="duplicateText"
405-
>
406-
First Text
407-
</Text>
408-
<Text
409-
testID="duplicateText"
410-
>
411-
Second Text
412-
</Text>
413-
<Text>
414-
0
415-
</Text>
416-
</View>"
417-
`;
418-
419-
exports[`debug: shallow with message 1`] = `
420-
"my other custom message
421-
422-
<View>
423-
<Text>
424-
Is the banana fresh?
425-
</Text>
426-
<Text
427-
testID="bananaFresh"
428-
>
429-
not fresh
430-
</Text>
431-
<TextInput
432-
placeholder="Add custom freshness"
433-
testID="bananaCustomFreshness"
434-
value="Custom Freshie"
435-
/>
436-
<TextInput
437-
defaultValue="What did you inspect?"
438-
placeholder="Who inspected freshness?"
439-
testID="bananaChef"
440-
value="I inspected freshie"
441-
/>
442-
<TextInput
443-
defaultValue="What banana?"
444-
/>
445-
<TextInput
446-
defaultValue="hello"
447-
value=""
448-
/>
449-
<MyButton
450-
onPress={[Function changeFresh]}
451-
>
452-
Change freshness!
453-
</MyButton>
454-
<Text
455-
testID="duplicateText"
456-
>
457-
First Text
458-
</Text>
459-
<Text
460-
testID="duplicateText"
461-
>
462-
Second Text
463-
</Text>
464-
<Text>
465-
0
466-
</Text>
467-
</View>"
468-
`;
469-
470370
exports[`debug: with message 1`] = `
471371
"my custom message
472372

src/__tests__/render-debug.test.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,19 @@ test('debug', () => {
9797

9898
screen.debug();
9999
screen.debug('my custom message');
100-
screen.debug.shallow();
101-
screen.debug.shallow('my other custom message');
102100
screen.debug({ message: 'another custom message' });
103101

104102
const mockCalls = jest.mocked(console.log).mock.calls;
105103
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
106104
expect(stripAnsi(mockCalls[1][0] + mockCalls[1][1])).toMatchSnapshot('with message');
107-
expect(stripAnsi(mockCalls[2][0])).toMatchSnapshot('shallow');
108-
expect(stripAnsi(mockCalls[3][0] + mockCalls[3][1])).toMatchSnapshot('shallow with message');
109-
expect(stripAnsi(mockCalls[4][0] + mockCalls[4][1])).toMatchSnapshot('another custom message');
105+
expect(stripAnsi(mockCalls[2][0] + mockCalls[2][1])).toMatchSnapshot('another custom message');
110106

111107
const mockWarnCalls = jest.mocked(console.warn).mock.calls;
112-
expect(mockWarnCalls[0]).toEqual([
113-
'Using debug("message") is deprecated and will be removed in future release, please use debug({ message; "message" }) instead.',
114-
]);
108+
expect(mockWarnCalls[0]).toMatchInlineSnapshot(`
109+
[
110+
"Using debug("message") is deprecated and will be removed in future release, please use debug({ message: "message" }) instead.",
111+
]
112+
`);
115113
});
116114

117115
test('debug changing component', () => {

src/__tests__/screen.test.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@ test('screen throws without render', () => {
5555
expect(() => screen.root).toThrow('`render` method has not been called');
5656
expect(() => screen.UNSAFE_root).toThrow('`render` method has not been called');
5757
expect(() => screen.debug()).toThrow('`render` method has not been called');
58-
expect(() => screen.debug.shallow()).toThrow('`render` method has not been called');
5958
expect(() => screen.getByText('Mt. Everest')).toThrow('`render` method has not been called');
6059
});

src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DebugOptions } from './helpers/debug-deep';
1+
import { DebugOptions } from './helpers/debug';
22

33
/**
44
* Global configuration options for React Native Testing Library.

src/helpers/debug-shallow.ts

-22
This file was deleted.

src/helpers/debug-deep.ts renamed to src/helpers/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type DebugOptions = {
88
/**
99
* Log pretty-printed deep test component instance
1010
*/
11-
export default function debugDeep(
11+
export function debug(
1212
instance: ReactTestRendererJSON | ReactTestRendererJSON[],
1313
options?: DebugOptions | string,
1414
) {

src/render.tsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import act from './act';
55
import { addToCleanupQueue } from './cleanup';
66
import { getConfig } from './config';
77
import { getHostChildren } from './helpers/component-tree';
8-
import debugDeep, { DebugOptions } from './helpers/debug-deep';
9-
import debugShallow from './helpers/debug-shallow';
8+
import { debug, DebugOptions } from './helpers/debug';
109
import { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';
1110
import { validateStringsRenderedWithinText } from './helpers/string-validation';
1211
import { renderWithAct } from './render-act';
@@ -105,7 +104,7 @@ function buildRenderResult(
105104
unmount,
106105
rerender: update, // alias for `update`
107106
toJSON: renderer.toJSON,
108-
debug: debug(instance, renderer),
107+
debug: makeDebug(instance, renderer),
109108
get root(): ReactTestInstance {
110109
return getHostChildren(instance)[0];
111110
},
@@ -139,12 +138,9 @@ function updateWithAct(
139138
};
140139
}
141140

142-
export interface DebugFunction {
143-
(options?: DebugOptions | string): void;
144-
shallow: (message?: string) => void;
145-
}
141+
export type DebugFunction = (options?: DebugOptions | string) => void;
146142

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

162158
const json = renderer.toJSON();
163159
if (json) {
164-
return debugDeep(json, debugOptions);
160+
return debug(json, debugOptions);
165161
}
166162
}
167-
debugImpl.shallow = (message?: string) => debugShallow(instance, message);
168163
return debugImpl;
169164
}

src/screen.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const notImplemented = () => {
1010
const notImplementedDebug = () => {
1111
throw new Error(SCREEN_ERROR);
1212
};
13-
notImplementedDebug.shallow = notImplemented;
1413

1514
interface Screen extends RenderResult {
1615
isDetached?: boolean;

src/shallow.ts

-18
This file was deleted.

typings/index.flow.js

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ type DebugOptions = {
276276

277277
type Debug = {
278278
(options?: DebugOptions | string): void,
279-
shallow: (message?: string) => void,
280279
};
281280

282281
type Queries = ByTextQueries &

website/docs/MigrationV13.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## @@ -0,0 +1,20 @@
2-
31
id: migration-v13
42
title: Migration to 13.0
53

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

63+
## Removed `debug.shallow`
64+
65+
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).
66+
6567
# Other changes
6668

6769
## Updated `flushMicroTasks` internal method

0 commit comments

Comments
 (0)