When running jest that calls the below function in a test I get TypeError: payload must be an instance of Uint8Array
. The code builds, and runs fine in node (not working in jest).
import { SignJWT, jwtVerify, JWTVerifyOptions, JWTPayload } from 'jose'; //used for jwt
export async function get_jwt_token() {
const sig = (new TextEncoder().encode('MYSECRETKEY543534')) as Uint8Array;
const token = await new SignJWT()
.sign(sig); //causes TypeError: payload must be an instance of Uint8Array in jest
return token;
}
it('get_jwt_token should not cause an error', async () => {
const token = await get_jwt_token();
console.log(token);
});
I am using the latest versions of jest and jose but also tried older versions. I expect it to work normally without error. I even tried console.log(sig) inside of get_jwt_token and it shows the type as Uint8Array during jest test so I am not understanding the problem.
Am I missing something? Any help would be appreciated, thank you.
rogue94 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.