Skip to content

Commit

Permalink
Relay: Forward Compatibility in Jest Tests for enableRefAsProp (#4695)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #4695

Refactors a few Jest unit tests so that they're resilient to upcoming changes in React, when `enableRefAsProp` is enabled.

Reviewed By: voideanvalue

Differential Revision: D57133519

fbshipit-source-id: 846bfc07089c024745ffe03f49bbacfafe40a5e5
  • Loading branch information
yungsters authored and facebook-github-bot committed May 9, 2024
1 parent aa9f644 commit d048828
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ describe('ReactRelayFragmentContainer with fragment ownership', () => {
user: UserFragment,
};
variables = {rootVariable: 'root'};
TestComponent = render;
TestComponent = ({ref, ...props}) => {
// Omit `ref` for forward-compatibility with `enableRefAsProp`.
return render(props);
};
TestComponent.displayName = 'TestComponent';
TestContainer = ReactRelayFragmentContainer.createContainer(
TestComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ describe('ReactRelayFragmentContainer', () => {
user: UserFragment,
};

TestComponent = render;
TestComponent = ({ref, ...props}) => {
// Omit `ref` for forward-compatibility with `enableRefAsProp`.
return render(props);
};
TestComponent.displayName = 'TestComponent';
TestContainer = ReactRelayFragmentContainer.createContainer(
TestComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ describe('ReactRelayPaginationContainer with fragment ownership', () => {
count,
};
});
TestComponent = render;
TestComponent = ({ref, ...props}) => {
// Omit `ref` for forward-compatibility with `enableRefAsProp`.
return render(props);
};
TestComponent.displayName = 'TestComponent';
TestContainer = ReactRelayPaginationContainer.createContainer(
TestComponent,
Expand Down Expand Up @@ -374,7 +377,7 @@ describe('ReactRelayPaginationContainer with fragment ownership', () => {
loadMore(1, jest.fn());
expect(render.mock.calls.length).toBe(1);

TestComponent.mockClear();
render.mockClear();
TestChildComponent.mockClear();
ReactTestRenderer.act(() => {
environment.mock.resolve(UserQuery, {
Expand Down Expand Up @@ -915,7 +918,7 @@ describe('ReactRelayPaginationContainer with fragment ownership', () => {
};
expect(environment.mock.isLoading(UserQuery, variables)).toBe(true);

TestComponent.mockClear();
render.mockClear();
TestChildComponent.mockClear();
environment.mock.resolve(UserQuery, {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ describe('ReactRelayPaginationContainer', () => {
count,
};
});
TestComponent = render;
TestComponent = ({ref, ...props}) => {
// Omit `ref` for forward-compatibility with `enableRefAsProp`.
return render(props);
};
TestComponent.displayName = 'TestComponent';
TestContainer = ReactRelayPaginationContainer.createContainer(
TestComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ describe('ReactRelayRefetchContainer', () => {
return <ContextGetter />;
});
variables = {};
TestComponent = render;
TestComponent = ({ref, ...props}) => {
// Omit `ref` for forward-compatibility with `enableRefAsProp`.
return render(props);
};
TestComponent.displayName = 'TestComponent';
TestContainer = ReactRelayRefetchContainer.createContainer(
TestComponent,
Expand Down

0 comments on commit d048828

Please sign in to comment.