This is how I'm testing a very simple reactJS component with react-apollo via jestJS. I'm also using the coverage function of jest.
But the coverage shows me, that I'm missing to test the line options: (props) => ({ in the graphql().
How should I do this correctly?
Example.js
import React, { Component } from 'react'
import { graphql, compose } from 'react-apollo'
import { getPostsQuery } from './graphql/query'
export class Example extends Component {
render () {
const { data } = this.props
const { getPosts, loading } = data
return (
<div id="article">
{
getPosts.map(post => {
return (<div>{post.content}</div>)
})
}
</div>
)
}
}
export default compose(
graphql(
getPostsQuery, {
options: (props) => ({
variables: {
articleId: props.articleId
}
})
}
)
)(Example)
Unit test
import React from 'react'
import { shallow } from 'enzyme'
import { Example } from './components/Example'
describe('<Example />', () => {
it('should render #article element', () => {
wrapper = shallow(<Example data={data} />)
expect(wrapper.find('#article')).toHaveLength(1)
})
})