Last active
December 23, 2019 14:00
-
-
Save bobmacneal/3544d353da1be7f355fa5b5171fef8ed to your computer and use it in GitHub Desktop.
A function to write a Cypress.io fixture (for subsequent XHR mocking) via a "temporarily live" API request
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('Cypress Request to JSON Writer', () => { | |
const JSON_PLACEHOLDER_API_URL = 'https://jsonplaceholder.typicode.com' | |
const FILENAME = 'users.json' | |
it('Writes XHR to a JSON fixture file', () => { | |
const url = `${JSON_PLACEHOLDER_API_URL}/users` // the API call | |
// Use cy.request to hit the API url. Add bearer token if auth required for API. | |
cy.request({ | |
url: url, | |
auth: { | |
bearer: '', | |
}, | |
}).then( | |
response => { | |
// use the response.body returned from API to write a fixture. | |
cy.writeFile(`cypress/fixtures/${FILENAME}`, response.body) | |
} | |
) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment