Created
March 15, 2018 18:23
-
-
Save axle07/758885e866987be96f8dbfd8b19a3d5e to your computer and use it in GitHub Desktop.
Cypress.js: Assert that an XHR POST was successful.
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
describe('XHR form submission test', () => { | |
before(() => { | |
cy.visit('/testurl') | |
}) | |
it('successfully submits an XHR on form submission', () => { | |
cy.get('[data-test="form"]').within(() => { | |
cy.get('#test-input').type('spyfu.com') | |
cy.route('POST', '/sumbit/here').as('postForm') // note that the route needs to match trailing slashes | |
cy.get('button[type="submit"]').click() | |
.wait('@postForm') | |
.its('status').should('be', 200) | |
}).then(() => { | |
cy.get('[data-test="success-message"]').should('exist') | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed to do that.