Custom Cypress Commands
I've been loving my first forays into [Cypress](https://www.cypress.io/) integration testing. It feels really well made.
Today I learned how to create a custom Cypress command. Logging into the application is a classic use-case: I need to do it in almost every test, and I'd like a function that accepts arguments and centralizes the DOM manipulation.
Here it is:
```javascript
// cypress/support/commands.js
Cypress.Commands.add('signIn', ({ email, password }) => {
cy.visit('/sign-in');
cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('form').submit();
});
```
The command is now available in any test without an explicit import:
```javascript
cy.signIn({ email: 'dev@hashrocket.com', password: 'password' });
```
Abstraction!
[docs](https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax)
jakeworth
August 9, 2018