Using MockedProvider in Storybook doesn't seem to return anything.
When wrapping my component in the MockedProvider, it no longer throws an error that there's no Apollo client. So this proves that the MockProvider "works"
Intended outcome:
The following hook should return the data that's in the mock:
const { loading, error, data } = useQuery(LATEST_SELL_SIGNALS)
Actual outcome:
loading is true on first render and false on the second render
data is undefined
error is undefined
The fact that the loading props are working, should also suggest MockedProvider is running.
Example story:
import React from 'react'
import { MockedProvider } from '@apollo/react-testing'
import { LATEST_SELL_SIGNALS } from '~/common/queries'
import LatestSells from './LatestSells'
const mocks = [
{
request: {
query: LATEST_SELL_SIGNALS,
},
result: {
data: {
yourData: { name: 'Storybook Data' },
},
},
},
]
export default {
title: 'Sales Components'
}
export const latest_sells = () => {
return (
<MockedProvider mocks={mocks}>
<LatestSells />
</MockedProvider>
)
}
Where the LATEST_SELL_SIGNALS is this file:
import { gql } from 'apollo-boost'
export const LATEST_SELL_SIGNALS = gql`
query {
latestSellSignalsList(orderBy: createdAt_DESC, first: 10) {
items {
name
ticker
boughtAt
soldAt
}
}
}
`
the Component I'm wrapping is using react hooks like this:
const { loading, error, data } = useQuery(LATEST_SELL_SIGNALS)
The import for the query is the same in the Component as it is in the mock
please note this all works just fine with my normal Apollo Provider, I'm only having issues with the MockProvider not doing it's thing.
The component. also renders fine
Version 3.1.4
