Bonus Lesson 21: intercept and confirm navigator.sendBeacon calls

Описание к видео Bonus Lesson 21: intercept and confirm navigator.sendBeacon calls

This is a bonus lesson from my "Cypress Network Testing Exercises" course https://cypress.tips/courses which shows spying on the application making "navigator.sendBeacon" calls to send small analytics events to the server. We confirm that the browser is sending plain text, converting it to a JSON object, and confirming it has the property "fruit". We then ensure that fruit is shown on the loaded page.

cy.intercept('POST', '/got-fruit').as('beacon')
cy.visit('/')
cy.wait('@beacon')
.its('request.body')
.should('be.a', 'string')
.then(JSON.parse)
.should('have.property', 'fruit')
.then(function (fruit) {
cy.contains('#fruit', fruit)
})

See the "navigator.sendBeacon" docs at https://developer.mozilla.org/en-US/d... and find an example application to test at https://github.com/bahmutov/fastify-e...

Комментарии

Информация по комментариям в разработке