#jest TypeError: payload must be an instance of Uint8Array

2 messages · Page 1 of 1 (latest)

quartz aspen
#

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.

vale valveBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)