0

I'm trying to test that the application redirects the user away from the authenticated route since they are not an admin.

But I need a way to wait for all redirects to finish before I call getCurrentUrl()

    it('should not allow regular user access', async (test) => {
  await test.remote
      .then(e2e.impersonate('test@test.com'))
      .get('/protected-route')
      //.waitForAllRedirects()
      .getCurrentUrl()
      .then(url => {
        console.log('url', url);
        expect(url.indexOf('/landing-page')).not.toBe(-1);
        return true;
      });
});
chovy
  • 72,281
  • 52
  • 227
  • 295

1 Answers1

1

Probably the simplest thing to do is to look for content that should be on the non-protected page rather than the protected page. Once you've found the expected content, check the URL to verify you're where you should be.

it('should not allow regular user access', test => {
  return test.remote
    .then(e2e.impersonate('test@test.com'))
    .get('/protected-route')
    .findByCssSelector('.something.that.should.be.visible')
    .getCurrentUrl()
    .then(url => {
      console.log('url', url);
      expect(url.indexOf('/landing-page')).not.toBe(-1);
      return true;
    });
});
jason0x43
  • 3,363
  • 1
  • 16
  • 15