Today I Learned - Rocky Kev

TIL about Cypress Custom Commands

POSTED ON:

TAGS:

I really like Cypress as a testing suite. It's really pwowerful and has a lot of features.

Today I learned adding custom commands to Cypress to abstract common patterns:

Cypress.Commands.add('login', () => {
cy.visit('/login');
cy.get('input[name=email]').type('foo@bar.com');
cy.get('input[name=password]').type('password');
cy.get('form').submit();
});

// Anywhere else
cy.login();

via Cypress or how I learned to stop worrying and love E2E


Related TILs

Tagged:

TIL Scoping with Cypress

So you wanted to find a specific element called `heading`. But you have a BUNCH of elements called `heading`. By using `within()` helper, you can force it to only look inside `main` elements.

TIL MSW for mocking

MSW is a API mocking tool. Mock by intercepting requests on the network level. Seamlessly reuse the same mock definition for testing, development, and debugging.

TIL writing a clean function

Write an assert at the beginning of the function. Then, write down all the conditions that must be met.