Description
Current behavior:
Cypress makes invoking methods on native DOM elements less expressive than it could be.
My use case: I want to call an <input>
's checkValidity
method. According to the FAQ I basically need to do this:
cy.get('input')
.should($input => {
expect($input.get(0).checkValidity()).not.to.equal(false)
})
This basically works, but Cypress' otherwise amazing expressivity takes a hard hit here since the logs naturally don't know anything about the invocation:
→ The assertion is shown, however the desired behaviour would be to also have the invocation listed in the log, as it does when running .invoke()
.
Desired behavior:
I'd like to advocate for a built-in way to invoke native DOM methods. Some quick thinking lead me to two possible solutions:
The obvious one. Provide an .invokeNative()
method on the Cypress wrapper. However having two methods for basically the same thing may not be desirable.
The embracing-jQuery one. Extend the built-in jQuery copy with a native
method that proxies native DOM calls. I've tried this myself, but you apparently have shielded the Cypress.$.fn
away from curious developers. 🙃
The implementation would basically be this:
Cypress.$.fn.native = (method, ...args) => {
return this.get(0)[method](...args)
}
which would allow to invoke native DOM functionality as easy as:
cy.get('input')
.invoke('native', 'checkValidity')
.should('not.equal', false)
I'd love to hear your feedback on this.
- Operating System: macOS 10.12.6
- Cypress Version: Beta 1.0.2
- Browser Version: Chrome 61