Integrating with other tools
mockit exposes APIs to modify its internal state. You can use this to your benefit.
Integrating with Cypress.io
Cypress.Commands.add('resetMockit', () => {
const defaultLog = {
displayName: 'RESET SERVER STATE',
};
// Makes request to mockit to reset server state
return fetch('http://localhost:3000/mockit/api/reset', {
method: 'PUT',
}).then(() => {
return Cypress.log({
...defaultLog,
});
}).catch(err => {
return Cypress.log({
...defaultLog,
message: err,
});
});
});
Cypress.Commands.add('switchContract', id => {
const defaultLog = {
displayName: 'SWITCH CONTRACT',
};
// Makes request to mockit to update active fixture
return fetch('http://localhost:3000/mockit/api', {
method: 'PUT',
body: JSON.stringify({ id }),
headers: {
'Content-Type': 'application/json',
},
}).then(() => {
return Cypress.log({
...defaultLog,
message: `Switched to ${id}`,
});
}).catch(() => {
return Cypress.log({
...defaultLog,
message: 'Failed to switch',
});
});
});
Last updated