Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react'
import { GraphQLTaggedNode, Variables } from 'relay-runtime'
import { QueryRenderer } from 'react-relay'
import hoistStatics from 'hoist-non-react-statics'
import { createMockEnvironment } from 'relay-test-utils'
import { Environment } from '.'
interface Config {
query?: GraphQLTaggedNode
queriesParams?: (props: Object) => Object
variables?: Variables
hideSplash?: boolean
}
export const env = createMockEnvironment()
export default function createQueryRenderer(
FragmentComponent: React.ComponentType,
Component: React.ComponentType,
config: Config,
LoadingComponent?: React.ComponentType
) {
const { query, queriesParams } = config
function QueryRendererWrapper(props: Object) {
const variables = (queriesParams ? queriesParams(props) : config.variables) as Variables
return (
Environment.mock.resolveMostRecentOperation((operation) =>
MockPayloadGenerator.generate(operation),
);
env.mock.resolveMostRecentOperation(operation => MockPayloadGenerator.generate(operation))
env.mock.resolveMostRecentOperation(op => MockPayloadGenerator.generate(op))
environment.mock.resolveMostRecentOperation(operation => {
return MockPayloadGenerator.generate(operation)
})
expect(renderer.toJSON()).toMatchSnapshot()
env.mock.resolveMostRecentOperation(operation => MockPayloadGenerator.generate(operation))
jest.mock("lib/relay/createEnvironment", () => ({
defaultEnvironment: require("relay-test-utils").createMockEnvironment(),
}))
jest.mock("lib/relay/createEnvironment", () => ({
defaultEnvironment: require("relay-test-utils").createMockEnvironment(),
}))
beforeEach(() => {
environment = createMockEnvironment()
;(useTracking as jest.Mock).mockImplementation(() => {
return {
trackEvent,
}
})
})