Skip to content

Instantly share code, notes, and snippets.

@joeeames
Created October 27, 2018 06:27
Show Gist options
  • Save joeeames/64cb98c57a9c49ae19b175f715b21653 to your computer and use it in GitHub Desktop.
Save joeeames/64cb98c57a9c49ae19b175f715b21653 to your computer and use it in GitHub Desktop.
describe('Home Page', () => {
beforeEach(() => {
})
it('should have title', () => {
cy.seedAndVisit();
cy.contains('Angular (2+)');
});
it('should have a default article', () => {
cy.seedAndVisit();
cy.contains("Let's Get Started with Angular");
});
describe('search', () => {
beforeEach(() => {
})
it('should search with real data', () => {
cy.server();
cy.visit('/');
cy.get('input.search').type('night');
cy.get('.search-button').click();
cy.get('app-article').should('have.length', 1);
})
it('should filter to match when searching', () => {
cy.seedAndVisit();
cy.get('input.search').type('forms');
cy.get('.search-button').click();
cy.get('app-article').should('have.length', 1);
})
})
describe('tags filtering', () => {
it('should only show the one returned search article when a tag is selected', () => {
cy.seedAndVisit(undefined, undefined, undefined, 'fixture:article2');
cy.get('div.tags').eq(3).click();
cy.get('app-article')
.should('have.length', 1)
.contains('Angular Forms FAQ');
})
it('should display all the related tags', () => {
cy.seedAndVisit(undefined, undefined, undefined, 'fixture:article2');
cy.get('div.tags').eq(3).click();
cy.get('div.tags').as('tags').should('have.length', 3);
cy.get('@tags').eq(0).contains('getting-started');
cy.get('@tags').eq(1).contains('forms');
cy.get('@tags').eq(2).contains('typescript');
})
it('should display the selected tag', () => {
cy.seedAndVisit(undefined, undefined, undefined, 'fixture:article2');
cy.get('div.tags').eq(3).click();
cy.get('div.tags a.bold')
.should('have.length', 1)
.contains('getting-started');
})
})
})
@bahmutov
Copy link

  1. empty beforeEach block
  2. test 'should search with real data' calls cy.server() to start Cypress proxy but never defines any routes to spy or stub, so it does it for nothing
  3. can't you use destructuring in the custom command rather than pass cy.seedAndVisit(undefined, undefined, undefined, 'fixture:article2')?
  4. the selector names might be what you need like cy.get('div.tags') but they less than perfect I think. Our guide in https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements goes into details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment