|
1 | 1 | /* eslint-disable no-console */
|
2 | 2 | import * as React from 'react';
|
3 |
| -import { View, Text, TextInput, Pressable, SafeAreaView } from 'react-native'; |
4 |
| -import { render, fireEvent, RenderAPI } from '..'; |
5 |
| - |
6 |
| -type ConsoleLogMock = jest.Mock<typeof console.log>; |
7 |
| - |
8 |
| -beforeEach(() => { |
9 |
| - jest.spyOn(console, 'warn').mockImplementation(() => {}); |
10 |
| -}); |
| 3 | +import { View, Text, TextInput, Pressable } from 'react-native'; |
| 4 | +import { render, screen, fireEvent, RenderAPI } from '..'; |
11 | 5 |
|
12 | 6 | const PLACEHOLDER_FRESHNESS = 'Add custom freshness';
|
13 | 7 | const PLACEHOLDER_CHEF = 'Who inspected freshness?';
|
@@ -156,7 +150,6 @@ test('unmount should handle cleanup functions', () => {
|
156 | 150 |
|
157 | 151 | test('toJSON renders host output', () => {
|
158 | 152 | const { toJSON } = render(<MyButton>press me</MyButton>);
|
159 |
| - |
160 | 153 | expect(toJSON()).toMatchSnapshot();
|
161 | 154 | });
|
162 | 155 |
|
@@ -226,38 +219,19 @@ test('returns composite UNSAFE_root', () => {
|
226 | 219 | expect(UNSAFE_root.props.testID).toBe('inner');
|
227 | 220 | });
|
228 | 221 |
|
229 |
| -test('returns container', () => { |
230 |
| - const { container } = render(<View testID="inner" />); |
| 222 | +test('container displays deprecation', () => { |
| 223 | + const view = render(<View testID="inner" />); |
231 | 224 |
|
232 |
| - const mockCalls = (console.warn as any as ConsoleLogMock).mock.calls; |
233 |
| - expect(mockCalls[0][0]).toMatchInlineSnapshot(` |
234 |
| - "'container' property is deprecated and has been renamed to 'UNSAFE_root'. |
| 225 | + expect(() => view.container).toThrowErrorMatchingInlineSnapshot(` |
| 226 | + "'container' property has been renamed to 'UNSAFE_root'. |
235 | 227 |
|
236 | 228 | Consider using 'root' property which returns root host element."
|
237 | 229 | `);
|
| 230 | + expect(() => screen.container).toThrowErrorMatchingInlineSnapshot(` |
| 231 | + "'container' property has been renamed to 'UNSAFE_root'. |
238 | 232 |
|
239 |
| - expect(container).toBeDefined(); |
240 |
| - // `View` composite component is returned. This behavior will break if we |
241 |
| - // start returning only host components. |
242 |
| - expect(container.type).toBe(View); |
243 |
| - expect(container.props.testID).toBe('inner'); |
244 |
| -}); |
245 |
| - |
246 |
| -test('returns wrapper component as container', () => { |
247 |
| - type WrapperComponentProps = { children: React.ReactNode }; |
248 |
| - const WrapperComponent = ({ children }: WrapperComponentProps) => ( |
249 |
| - <SafeAreaView testID="wrapper">{children}</SafeAreaView> |
250 |
| - ); |
251 |
| - |
252 |
| - const { container } = render(<View testID="inner" />, { |
253 |
| - wrapper: WrapperComponent, |
254 |
| - }); |
255 |
| - |
256 |
| - expect(container).toBeDefined(); |
257 |
| - // `WrapperComponent` composite component is returned with no testID passed to |
258 |
| - // it. This behavior will break if we start returning only host components. |
259 |
| - expect(container.type).toBe(WrapperComponent); |
260 |
| - expect(container.props.testID).not.toBeDefined(); |
| 233 | + Consider using 'root' property which returns root host element." |
| 234 | + `); |
261 | 235 | });
|
262 | 236 |
|
263 | 237 | test('RenderAPI type', () => {
|
|
0 commit comments