samedi 6 mars 2021

Cypress won't redirect to home after login submit

I'm trying to test a redirect after the user login, but its not working. If I do it outside the test it works(it redirects to '/home' page).

The submit is handle with a dispatch from redux, but I don't think that's the problem because I tested before, with some changes and it worked.

This is the login form:

const submit = (data: AuthData) => {
    dispatch(login(data));
    router.push('/home');
  };

  return (
    <div>
      <form noValidate onSubmit={handleSubmit(submit)}>
        {inputs.map((input) => (
          <div key={input.name} className="text-left mb-3">
            <label htmlFor={input.name} className="form-label">
              {input.label}
            </label>
            <Input
              register={register}
              name={input.name}
              type={input.type}
              placeholder={input.placeholder}
              error={errors[input.name]}
            />
            <div className={'invalid-feedback'}>{errors[input.name]?.message}</div>
          </div>
        ))}

        <div className="text-center mt-3">
          <Button className={'btn btn-primary btn-lg btn-block'} type={ButtonType.submit}>
            Submit
          </Button>
        </div>
      </form>
    </div>
  );

This is the login test:

describe('Login Page', () => {
  it('Login correctly', () => {
      cy.get('#email').clear().type('user@mail.com');
      cy.get('#password').clear().type('123456');
      cy.get('.btn').click();
      cy.get('.btn').click();
      cy.get('[data-cy=home]');
    });
});

And this is the error that I'm getting enter image description here

Aucun commentaire:

Enregistrer un commentaire