Skip to content

Commit 09fbb4c

Browse files
committed
refactor: replace UNSAFE_root with container
1 parent c4a03a3 commit 09fbb4c

File tree

7 files changed

+12
-35
lines changed

7 files changed

+12
-35
lines changed

src/__tests__/render.test.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,12 @@ test('returns host root', () => {
204204
expect(screen.root.props.testID).toBe('inner');
205205
});
206206

207-
// test('returns composite UNSAFE_root', () => {
208-
// render(<View testID="inner" />);
209-
210-
// expect(screen.UNSAFE_root).toBeDefined();
211-
// expect(screen.UNSAFE_root.type).toBe(View);
212-
// expect(screen.UNSAFE_root.props.testID).toBe('inner');
213-
// });
214-
215-
test('container displays deprecation', () => {
207+
test('returns container', () => {
216208
render(<View testID="inner" />);
217209

218-
expect(() => (screen as any).container).toThrowErrorMatchingInlineSnapshot(`
219-
"'container' property has been renamed to 'UNSAFE_root'.
220-
221-
Consider using 'root' property which returns root host element."
222-
`);
210+
expect(screen.container).toBeDefined();
211+
expect(screen.container.type).toBe('CONTAINER');
212+
expect(screen.container.props).toEqual({});
223213
});
224214

225215
test('RenderAPI type', () => {

src/__tests__/screen.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test('screen works with nested re-mounting rerender', () => {
5353

5454
test('screen throws without render', () => {
5555
expect(() => screen.root).toThrow('`render` method has not been called');
56-
expect(() => screen.UNSAFE_root).toThrow('`render` method has not been called');
56+
expect(() => screen.container).toThrow('`render` method has not been called');
5757
expect(() => screen.debug()).toThrow('`render` method has not been called');
5858
expect(() => screen.debug.shallow()).toThrow('`render` method has not been called');
5959
expect(() => screen.getByText('Mt. Everest')).toThrow('`render` method has not been called');

src/helpers/__tests__/component-tree.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ describe('getHostSiblings()', () => {
3737
});
3838
});
3939

40-
describe('getUnsafeRootElement()', () => {
41-
it('returns UNSAFE_root for mounted view', () => {
40+
describe('getRootElement()', () => {
41+
it('returns container for mounted view', () => {
4242
render(
4343
<View>
4444
<View testID="view" />
4545
</View>,
4646
);
4747

4848
const view = screen.getByTestId('view');
49-
expect(getRootElement(view)).toEqual(screen.UNSAFE_root);
49+
expect(getRootElement(view)).toEqual(screen.container);
5050
});
5151
});

src/matchers/__tests__/utils.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('checkHostElement allows rejects composite element', () => {
2525

2626
expect(() => {
2727
// @ts-expect-error
28-
checkHostElement(screen.UNSAFE_root, fakeMatcher, {});
28+
checkHostElement(screen.container, fakeMatcher, {});
2929
}).toThrow(/value must be a host element./);
3030
});
3131

src/matchers/to-be-on-the-screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function toBeOnTheScreen(this: jest.MatcherContext, element: HostElement)
99
checkHostElement(element, toBeOnTheScreen, this);
1010
}
1111

12-
const pass = element === null ? false : screen.UNSAFE_root === getRootElement(element);
12+
const pass = element === null ? false : screen.container === getRootElement(element);
1313

1414
const errorFound = () => {
1515
return `expected element tree not to contain element, but found\n${formatElement(element)}`;

src/render.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,10 @@ function buildRenderResult(
111111
get root(): HostElement {
112112
return renderer.root;
113113
},
114-
UNSAFE_root: instance,
114+
container: instance,
115115
};
116116

117-
// Add as non-enumerable property, so that it's safe to enumerate
118-
// `render` result, e.g. using destructuring rest syntax.
119-
Object.defineProperty(result, 'container', {
120-
enumerable: false,
121-
get() {
122-
throw new Error(
123-
"'container' property has been renamed to 'UNSAFE_root'.\n\n" +
124-
"Consider using 'root' property which returns root host element.",
125-
);
126-
},
127-
});
128-
129117
setRenderResult(result);
130-
131118
return result;
132119
}
133120

src/screen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const defaultScreen: Screen = {
2121
get root(): HostElement {
2222
throw new Error(SCREEN_ERROR);
2323
},
24-
get UNSAFE_root(): HostElement {
24+
get container(): HostElement {
2525
throw new Error(SCREEN_ERROR);
2626
},
2727
debug: notImplementedDebug,

0 commit comments

Comments
 (0)