Created
March 18, 2018 08:41
-
-
Save NicholasBoll/98988f10efa5bb0df009151ce02ce2aa to your computer and use it in GitHub Desktop.
Using Jest's expect using Cypress's should shorthand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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