Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NicholasBoll/98988f10efa5bb0df009151ce02ce2aa to your computer and use it in GitHub Desktop.
Save NicholasBoll/98988f10efa5bb0df009151ce02ce2aa to your computer and use it in GitHub Desktop.
Using Jest's expect using Cypress's should shorthand
import expect from 'expect'
// Put this in cypress/support/commands.js to use everywhere
Cypress.Commands.overwrite('should', (originalFn, subject, expectation, ...args) => {
// See if the expectation is a string and if it is a member of Jest's expect
if (typeof expectation === 'string' && expect(subject)[expectation]) {
return originalFn(subject, (s) => expect(s)[expectation](...args))
}
return originalFn(subject, expectation, ...args)
})
describe('page', () => {
it('should allow should(string) style matching from jest', () => {
cy.wrap(5).should('toBe', 5)
cy.wrap({ foo: 'bar' }).should('toHaveProperty', 'foo', 'bar')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment