Skip to content

Instantly share code, notes, and snippets.

@bobbyg603
Last active June 3, 2022 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbyg603/d3692036e13c25a6be4714ef75da75e2 to your computer and use it in GitHub Desktop.
Save bobbyg603/d3692036e13c25a6be4714ef75da75e2 to your computer and use it in GitHub Desktop.
3 and 1/2 Reasons Your Tests Should Be Stateless
describe('Users Table', () => {
  const user1 = 'bobby@bugsplat.com';
  const user2 = 'bobbyg603@pm.me';

  beforeEach(() => {
+   cy.addUser(user1);
    cy.visit('/users');
  });

  it('should add a user to the table', () => {
-   cy.addUser(user1);
    cy.get('[data-cy=users-table]').should('contain.text', user1);
  });

  it('should display filtered table containing user1 and not user2', () => {
    cy.addUser(user2);
    cy.filterByUser(user1);
    cy.get('[data-cy=users-table]')
      .should('contain.text', user1)
      .should('not.contain.text', user2);
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment