# Testing Queries
Lets assume you have a TodoList component that fires a graphql query to fetch the list
from an API end point. Something like this:
```js
import { Query } from 'react-apollo';
const query = gql`
query GetItems {
items {
id
name
}
}
`;
const TodoList = () =>
{({ data: { items = [] } = {}, error, loading }: any) =>
if (loading) return Loading...
;
if (error) return {error.message}
;
return (
{items.map(item =>
- {item.name}
)}
);
}
;
```
Here is how you can test it with enzyme and graphql-mock:
```js
import { mount } from 'enzyme';
import { ApolloProvider } from 'react-apollo';
import graphqlMock from './graphql';
const render = () => mount(
);
describe('TodoList', () => {
it('renders todo items good', () => {
graphqlMock.expect(query).reply({ // <- `query` from the code above
items: [
{ id: '1', name: 'one' },
{ id: '2', name: 'two' }
]
});
expect(render().html()).toEqual('
');
});
it('renders loading state too', () => {
graphqlMock.expect(query).loading(true);
expect(render().html()).toEqual('Loading...
');
});
it('renders errors when API fails', () => {
graphqlMock.expect(query).fails('everything is terrible');
expect(render().html()).toEqual('everything is terrible
');
})
});
```
Please refer to the [API Documentation](./api.md) for more detailed information