Skip to content

fix: disable container deprecation warning (main) #1362

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 2 commits into from
Mar 8, 2023
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
17 changes: 8 additions & 9 deletions src/__tests__/render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import * as React from 'react';
import { View, Text, TextInput, Pressable, SafeAreaView } from 'react-native';
import { render, fireEvent, RenderAPI } from '..';

type ConsoleLogMock = jest.Mock<typeof console.log>;

beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {});
});
Expand Down Expand Up @@ -229,13 +227,6 @@ test('returns composite UNSAFE_root', () => {
test('returns container', () => {
const { container } = render(<View testID="inner" />);

const mockCalls = (console.warn as any as ConsoleLogMock).mock.calls;
expect(mockCalls[0][0]).toMatchInlineSnapshot(`
"'container' property is deprecated and has been renamed to 'UNSAFE_root'.

Consider using 'root' property which returns root host element."
`);

expect(container).toBeDefined();
// `View` composite component is returned. This behavior will break if we
// start returning only host components.
Expand Down Expand Up @@ -264,3 +255,11 @@ test('RenderAPI type', () => {
render(<Banana />) as RenderAPI;
expect(true).toBeTruthy();
});

test('returned output can be spread using rest operator', () => {
// Next line should not throw
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { rerender, ...rest } = render(<View testID="inner" />);
expect(rest).toBeTruthy();
expect(console.warn).not.toHaveBeenCalled();
});
10 changes: 5 additions & 5 deletions src/helpers/__tests__/getTextContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getTextContent } from '../getTextContent';

test('getTextContent with simple content', () => {
const view = render(<Text>Hello world</Text>);
expect(getTextContent(view.container)).toBe('Hello world');
expect(getTextContent(view.root)).toBe('Hello world');
});

test('getTextContent with null element', () => {
Expand All @@ -18,7 +18,7 @@ test('getTextContent with single nested content', () => {
<Text>Hello world</Text>
</Text>
);
expect(getTextContent(view.container)).toBe('Hello world');
expect(getTextContent(view.root)).toBe('Hello world');
});

test('getTextContent with multiple nested content', () => {
Expand All @@ -27,7 +27,7 @@ test('getTextContent with multiple nested content', () => {
<Text>Hello</Text> <Text>world</Text>
</Text>
);
expect(getTextContent(view.container)).toBe('Hello world');
expect(getTextContent(view.root)).toBe('Hello world');
});

test('getTextContent with multiple number content', () => {
Expand All @@ -36,7 +36,7 @@ test('getTextContent with multiple number content', () => {
<Text>Hello</Text> <Text>world</Text> <Text>{100}</Text>
</Text>
);
expect(getTextContent(view.container)).toBe('Hello world 100');
expect(getTextContent(view.root)).toBe('Hello world 100');
});

test('getTextContent with multiple boolean content', () => {
Expand All @@ -45,5 +45,5 @@ test('getTextContent with multiple boolean content', () => {
<Text>Hello{false}</Text> <Text>{true}world</Text>
</Text>
);
expect(getTextContent(view.container)).toBe('Hello world');
expect(getTextContent(view.root)).toBe('Hello world');
});
5 changes: 0 additions & 5 deletions src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ function buildRenderResult(
UNSAFE_root: instance,
get container() {
if (!getConfig().useBreakingChanges) {
// eslint-disable-next-line no-console
console.warn(
"'container' property is deprecated and has been renamed to 'UNSAFE_root'.\n\n" +
"Consider using 'root' property which returns root host element."
);
return instance;
}

Expand Down