Skip to content

Instantly share code, notes, and snippets.

@pamo
Created July 9, 2019 17:39
Show Gist options
  • Save pamo/17d5f2ae222513c8e85e384abbde624b to your computer and use it in GitHub Desktop.
Save pamo/17d5f2ae222513c8e85e384abbde624b to your computer and use it in GitHub Desktop.
Cypress Workshop
describe('Mock XHR Calls', () => {
beforeEach(() => {
cy.server();
cy.route({
method: 'GET',
url: '/api/heroes/11',
response: { id: 11, name: 'Bob the Builder' }
}).as('heroGet');
cy.route({
method: 'PUT',
url: '/api/heroes/11',
response: { id: 22, name: 'Mr. Mean' }
}).as('heroUpdate');
});
it('should have unexpected response ', () => {
const expectedName = 'the Builder Man';
cy.visit('/detail/11');
cy.get('input')
.type('{home}{del}{del}{del}{del}{end} Man')
.should('have.value', expectedName);
cy.get('h2')
.first()
.should('have.text', `${expectedName.toUpperCase()} Details`);
cy.get('app-hero-detail button:nth-of-type(2)').click();
cy.wait('@heroUpdate');
cy.get('h2')
.first()
.should('have.text', `${expectedName.toUpperCase()} Details`);
cy.get('app-messages div')
.last()
.should('contain', 'HeroService: updated hero id=11');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment