Repository navigation
Replies: 2 comments 5 replies
|
This is not really a question specific to Keycloak JS, but rather to Jest and how it works internally. I would recommend that you you check out the help page for the Jest project, and try to find an answer there. |
1 reply
|
This worked for me : In your test file, you need to create the jest mock instance: and then in your actual test you need to mock the init promise resolved value :
|
4 replies
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.
Hi all, I am trying to mock keycloak-js so I can unit test my code using it.
When I try to mock init, I am not able to resolve the promise with something like the following:
jest.mock("keycloak-js", () => { return jest.fn().mockImplementation(() => { //mock constructor - working return { init: jest.fn().mockResolvedValue(true) } }) })I get the following whern trying to invoke init:
TypeError: Cannot read properties of undefined (reading 'then')
Any idea what I am doing wrong here?
P.S. Implementation is working fine. Passed QA and everything. I just need to add this unit test to satisfy company criteria
All reactions