Creating your first test in Cypress
A test in Cypress is commonly referred to as a spec, which stands for specification. We will be referring to them as specs for the remainder of this chapter. Let us begin by understanding how to write arrow functions and callback functions in JavaScript.
Creating arrow functions in JavaScript
Arrow functions are extremely handy, and they clean things up quite a bit. They were introduced in the ECMAScript 6 (ES6) version. The code snippet in Figure 5.8 shows a simple function to add two numbers. It takes two parameters and returns the sum. Let us turn this into an arrow function:
Figure 5.8 – Function to add two numbers
Instead of using the function keyword, we name it like a variable and use an equals sign to assign it to the body of the function. After the parameters, we use a symbol called fat arrow (=>). In the case of one-liner functions, we can further simplify them by removing the curly braces surrounding...