Testing Asking a Question
Learn to test your end points with Cypress in React.
We'll cover the following...
We are going to implement a test on our app using Cypress; the test signs in and then asks a question.
Testing with Cypress: Step-by-step guide
Carry out the following steps to do so:
Let’s create a new file called
qanda.js
in theintegration
folder, which can be found in thecypress
folder, with the following content:
describe('Ask question', () => {beforeEach(() => {cy.visit('/');});it('When signed in and ask a valid question, thequestion should successfully save', () => {});});
The describe
function allows us to group a collection of tests on a feature. The first parameter is the title for the group, while the second parameter is a function that contains the tests in the group.
The it
function allows us to define the actual test. The first parameter is the title for the test, while the second parameter is a function that contains the steps in the test.
The beforeEach
function allows us to define steps to be executed before each test runs. In our case, we are using the visit
command to navigate to the root of the app. Remember that the root URL for the app is defined in the baseUrl
setting in the cypress.json
file.
Let's add the following step to our test:
it('When signed in and ask a valid question, thequestion should successfully save', () => {cy.contains('Q & A');});
Here, we are checking that the page contains the Q
...