awslabs / aws-jwt-verify

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

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

Closed sandun86 closed 1 year ago

sandun86 commented 1 year 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 1 year 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 1 year ago

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