25
loading...
This website collects cookies to deliver better user experience
it('displays initial list of todos', () => {
cy.mockNetworkAdd({
Query: () => ({
todos: () => ([
{
id: '1',
title: 'Go shopping',
completed: true,
},
]),
}),
});
cy.get('li')
.eq(0)
.contains(/Go shopping/)
.should('exist');
});
cy.mockNetworkAdd({
Query: () => ({
todos: () => {
throw new Error('Oh dear');
},
}),
});
type Todo {
id: ID
title: String
completed: Boolean
}
type Query {
todo(id: ID!): Todo
}
cy.mockNetworkAdd({
Query: () => ({
todo: () => ({
title: 'I expect to be this'
})
}),
});
id
, title
and completed
the mock would still work. We would end up receiving something like:{
"id": 1,
"title": "I expect to be this",
"completed": false
}
id
and completed
are auto-mocked based on their type, so you can keep your tests streamlined and avoid providing a bunch of data you don't care about.Run the demo app: Change directory to /demo, install node_modules with yarn
, then run yarn start
Run the cypress tests: At the project root install node_modules again with yarn
and then run yarn cypress