mirror of
https://github.com/wassname/talk.git
synced 2026-07-12 18:32:58 +08:00
Hide forward ref and fix tests
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import React, { ComponentType, StatelessComponent } from "react";
|
||||
|
||||
// TODO: (cvle) This currently a workaround to hide ForwardRef from
|
||||
// enzyme which does not support it well yet.
|
||||
export default function hideForwardRef(component: ComponentType) {
|
||||
const wrapped: StatelessComponent = (props: any) =>
|
||||
React.createElement(component, props);
|
||||
wrapped.displayName = component.displayName;
|
||||
return wrapped;
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import {
|
||||
GraphQLTaggedNode,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import { wrapDisplayName } from "recompose";
|
||||
|
||||
import hideForwardRef from "./hideForwardRef";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
/**
|
||||
@@ -18,5 +21,10 @@ export default <T>(
|
||||
): InferableComponentEnhancerWithProps<
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createFragmentContainer(component, fragmentSpec) as any;
|
||||
> => (component: React.ComponentType<any>) => {
|
||||
const result = createFragmentContainer(component, fragmentSpec);
|
||||
result.displayName = wrapDisplayName(component, "Relay");
|
||||
// TODO: (cvle) We wrap this currently to hide the ForwardRef which is not
|
||||
// well supported yet in enzyme.
|
||||
return hideForwardRef(result) as any;
|
||||
};
|
||||
|
||||
@@ -5,8 +5,13 @@ import {
|
||||
GraphQLTaggedNode,
|
||||
RelayPaginationProp,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import {
|
||||
InferableComponentEnhancerWithProps,
|
||||
wrapDisplayName,
|
||||
} from "recompose";
|
||||
import { Variables } from "relay-runtime";
|
||||
|
||||
import hideForwardRef from "./hideForwardRef";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
// TODO: (cvle) at some point we might switch these to stock react-relay typings
|
||||
@@ -44,5 +49,14 @@ export default <T, QueryVariables, FragmentVariables>(
|
||||
): InferableComponentEnhancerWithProps<
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] } & { relay: RelayPaginationProp },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createPaginationContainer(component, fragmentSpec, connectionConfig) as any;
|
||||
> => (component: React.ComponentType<any>) => {
|
||||
const result = createPaginationContainer(
|
||||
component,
|
||||
fragmentSpec,
|
||||
connectionConfig
|
||||
);
|
||||
result.displayName = wrapDisplayName(component, "Relay");
|
||||
// TODO: (cvle) We wrap this currently to hide the ForwardRef which is not
|
||||
// well supported yet in enzyme.
|
||||
return hideForwardRef(result) as any;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,12 @@ import {
|
||||
GraphQLTaggedNode,
|
||||
RelayRefetchProp,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import {
|
||||
InferableComponentEnhancerWithProps,
|
||||
wrapDisplayName,
|
||||
} from "recompose";
|
||||
|
||||
import hideForwardRef from "./hideForwardRef";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
/**
|
||||
@@ -19,5 +24,10 @@ export default <T>(
|
||||
): InferableComponentEnhancerWithProps<
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] } & { relay: RelayRefetchProp },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createRefetchContainer(component, fragmentSpec, refetchQuery) as any;
|
||||
> => (component: React.ComponentType<any>) => {
|
||||
const result = createRefetchContainer(component, fragmentSpec, refetchQuery);
|
||||
result.displayName = wrapDisplayName(component, "Relay");
|
||||
// TODO: (cvle) We wrap this currently to hide the ForwardRef which is not
|
||||
// well supported yet in enzyme.
|
||||
return hideForwardRef(result) as any;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ exports[`renders correctly 1`] = `
|
||||
disableLoadMore={false}
|
||||
isClosed={false}
|
||||
onLoadMore={[Function]}
|
||||
user={null}
|
||||
/>
|
||||
`;
|
||||
|
||||
@@ -36,6 +37,7 @@ exports[`when has more comments renders hasMore 1`] = `
|
||||
hasMore={true}
|
||||
isClosed={false}
|
||||
onLoadMore={[Function]}
|
||||
user={null}
|
||||
/>
|
||||
`;
|
||||
|
||||
@@ -56,6 +58,7 @@ exports[`when has more comments when loading more disables load more button 1`]
|
||||
hasMore={true}
|
||||
isClosed={false}
|
||||
onLoadMore={[Function]}
|
||||
user={null}
|
||||
/>
|
||||
`;
|
||||
|
||||
@@ -76,5 +79,6 @@ exports[`when has more comments when loading more enable load more button after
|
||||
hasMore={true}
|
||||
isClosed={false}
|
||||
onLoadMore={[Function]}
|
||||
user={null}
|
||||
/>
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user