# Testing Mutations
Lets pretend you have a componet that creates new TODO items:
```js
import { Mutation } from 'react-apollo';
const mutation = gql`
mutation GetItems($name: String!) {
createItem(name: $name) {
id
name
}
}
`;
const CreatorComponent = () =>
{(createItem, { data, loading, error }: any) => {
if (loading) return Loading...
;
if (error) return {error.message}
;
if (data) return {data.createItem.name}
;
const onClick = () => createItem({ variables: { name: 'new item' } });
return ;
}}
;
```
Now here how you can test this component through and through with graphql-mock:
```js
const render = () => mount(
);
describe('CreatorComponent', () => {
it('renders good by default', () => {
expect(render().html()).toEqual('');
});
it('sends mutations and renders responses', () => {
graphqlMock.expect(mutation).reply({
createItem: { id: 1, name: 'new item' }
});
const wrapper = render();
wrapper.find('button').simulate('click');
expect(wrapper.html()).toEqual('
new item
');
});
it('sends correct variables with the request', () => {
const mock = graphqlMock.expect(mutation).reply({
createItem: { id: 1, name: 'new item' }
});
const wrapper = render();
wrapper.find('button').simulate('click');
expect(mock.calls[0]).toEqual([{ name: 'new item' }]);
});
it('can take a failure and live to fight another day', () => {
graphqlMock.expect(mutation).fail('everything is terrible');
const wrapper = render();
wrapper.find('button').simulate('click');
expect(wrapper.html()).toEqual('everything is terrible
');
});
});
```
Please refer to the [API Documentation](./api.md) for more detailed information