When running jest that calls the below function in a test I get TypeError: payload must be an instance of Uint8Array. The code runs fine normally in node. I have tried multiple different versions of jest, and jose to no avail. The test environment is jest-environment-jsdom. I cannot find any info about this online whatsoever.
import { SignJWT, jwtVerify, JWTVerifyOptions, JWTPayload } from 'jose'; //used for jwt
export async function get_jwt_token(
user_id: string,
) {
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('admin', 'my-password');
console.log(token);
});
Any help would be appreciated.