Can an Okta User be Mocked? #26891
Unanswered
ej2brown
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We cannot use a real user for testing (as shown in the Cypress Okta Authentication docs) and are required to mock one.
Issue: @okta/okta-auth-js cannot be mocked when it's a dependency in another function
Our normal flow:
Mock e2e flow:
/api/v1/authn
, usingcy.intercept
. The intercept sets mock tokens and redirects which works beautifully.cy.stubs
won't seem to work on the OktaAuth object. This means that the object fields cannot be mocked/stub. For example, We callOktaAuth.isLoginRedirect()
after the redirect.The stubbing of
OktaAuth.isLoginRedirect()
works when called in the cypress test file, but not when it's a dependency in another function - the mock always returns false when the stub is true.There seem to be related discussions on mocking/stubbing functions within modules (similar to our issue) but I'm not 100% sure if they're related or if this is related to OktaAuth.
Investigation of Sinon’s
I also investigated Sinon, which cy.stub uses stub | Cypress Documentation. They outline how to mock a dependency How to stub a dependency of a module.
The error I get is isLoginRedirect is non-configurable and non-writable

My question is can OktaAuth be stubbed in order to mock an Okta user?
Specs:
Beta Was this translation helpful? Give feedback.
All reactions