This repo is a wrapper around cy-spok, moving it into a custom command with the help of a string-to-function map. The motivation for this is to make it easier to write spok assertions in Cypress, without having to import cy-spok in every file.
npm i -D cypress-spok-command
# or
yarn add -D cypress-spok-command
Add the following to your commands file (cypress/support/commands.js
by default):
import spok from "cypress-spok-command";
Then inside a test you can immediately use the cy.spok()
command:
cy.spok(target, matcher);
e.g.
it('matches with spok!', () => {
cy.request('/someEndpoint').then((response) => {
// this could also be loaded from a fixture
const expectedResponse = {
foo: 1
bar: {
a: 1,
b: 2
}
}
cy.spok(response.body.data, expectedResponse)
})
})
More examples can be found in the test suite for this package, under the cypress/intergration
directory