Skip to content

Issues with Richtext and vitest #949

Open
@alvarosabu

Description

@alvarosabu

Describe the issue you're facing

User reported :

We are using Storyblok with nuxt and use the renderRichtext function, which is working fine. But, when we use it inside a vitest test, we get the following error and cannot find anything in the docs or elsewhere.
"Please initialize the Storyblok SDK before calling the renderRichText function"
What should we do?
Thanks!
And added some more details on that:
Yes you can. I don't know how it helps in this case, because we really do nothing but calling the function in our test and it fails with said error.

//useRichtext.nuxt.test.ts
import { expect, describe, it } from "vitest";
const testRichtextBlok = {
 type: "doc",
 content: [
   {
     type: "paragraph",
     content: [
       {
         text: "Ziel des Textes",
         type: "text",
         marks: [
           {
             type: "bold",
           },
         ],
       },
     ],
   },
 ],
};
describe("useRichtext", () => {
 it("returns correct template", () => {
   const template = renderRichText(testRichtextBlok);
   expect(template).toBeTruthy();
 });
});

Do you have a hint here, please? I guess that the function doesn't have access to the outside instance of the JS client?

Reproduction

N/A

Steps to reproduce

No response

System Info

Waiting for author

Used Package Manager

npm

Error logs (Optional)

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-author[Issue] Awaiting further information or action from the issue authorpending-triage[Issue] Ticket is pending to be prioritised

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions