mardi 11 février 2020

Cypress tests - redux store is empty

So I have a little problem with Cypress. I was trying to run some e2e tests with it. For the context, in the project I'm using react (functional components and hooks), redux and redux-saga as the middleware. So I basically logged into the app via POST request so that I was given a login cookie and the app wouldn't log me out. Then I went to one of the pages in the app. There a few things should happen:

  1. The call to get user data (it works, I get the correct data in response)

2.The user data should be saved in redux store.

  1. Another call afterwards to get some data for the page, it uses the user data, that was taken in point 1.

The second and third steps don't work though, as the user id in the body of my call in step 3 is empty. I console.logged the whole redux state in the app during tests and it is indeed empty. So it looks like there is some problem in either redux-saga or redux itself in saving data. It's kinda weird though, because cypress doesn't access these places, it runs on a deployed version of the app... (in the app it all works fine of course) Did anyone have such a problem or have an idea of how could I fix it? My test for the context:

 context('TEST', () => {
  it('test', () => {
    cy.request({
      method: 'POST',
      url: 'someUrl',
      body: JSON.stringify({ email: 'someEmail', password: 'somePassword' }),
      failOnStatusCode: false
    });
    cy.wait(2000); /* this was added when the test didn't work already, i thought it just might be some timing issue */
    cy.visit('someRoute');

  });
});

Aucun commentaire:

Enregistrer un commentaire