-
npm init
-
npm i express
-
npm i cypress --save-dev
-
npm cypress open
-
Run the all the test cases
npx cypress run --spec "cypress/e2e/api-tests/*.cy.js"
-
Run single test case at once
npx cypress run --spec "cypress/e2e/api-tests/getUsers.cy.js"
-
We use describe and it from Mocha and expect from the chai, we dont need to explicit download
-
GET CALL
-
POST CALL
-
USING Fixtures in POST CALL
-
PUT Call
-
Delete Call
-
Nesting of the Responses
-
Pros and Cons of Test cases
-
Stubbing , Intercept
-
Using Fixtures in Intercept
Pros and Cons
More likely to work in production Test coverage around server endpoints Great for traditional server-side HTML rendering
Requires seeding data Much slower Harder to test edge cases
Maniupulate acc to the needs in the local , no work is done on the server
Control of response bodies, status, and headers Can force responses to take longer to simulate network delay No code changes to your server or client code Fast, < 20ms response times
No guarantee your stubbed responses match the actual data the server sends No test coverage on some server endpoints Not as useful if you're using traditional server side HTML rendering
cy.intercept() is used to control the behavior of HTTP requests. You can statically define the body, HTTP status code, headers, and other response characteristics.