awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
594 stars 43 forks source link

How to mock CognitoJwtVerifier.create().verify - Jest - Unit Testing #138

Closed sandun86 closed 8 months ago

sandun86 commented 9 months ago

How can we mock the following code using Jest

    const verifier = CognitoJwtVerifier.create({
      userPoolId: 'userPoolId',
      tokenUse: 'access',
      clientId: 'clientId',
    });

    const payload = await verifier.verify(awsCognitoToken);
ottokruse commented 9 months ago

Hi @sandun86 what exactly do you want to do, what problem do you encounter?

Here's a simple mock:

const mock = { create: () => ({ verify: async (jwt) => ({ claim: "claim value" }) }) };
ottokruse commented 8 months ago

Closing for now, let us you if you still have questions