Unit testing Slices with Next JS, Vitest & JSX

Hi,

We'd like to unit test our Slices. However, creating a Slice in Slice Machine creates an index.js which is not testable with index.test.js or index.test.jsx unless we rename index.js to index.jsx.

There may be some Vitest configuration changes that would help us, but I'm wondering if Slice Machine can be config'd to code-generate an index.jsx instead of index.js for us. Renaming index.js to index.jsx isn't a real hardship but it does undermine the code generation / DX a touch so wanted to reach out. Thank you!

Hi!

You can already configure your Next adapter to create slice with the ````jsx extension :slightly_smiling_face:

You need to update your `slicemachine.config.json with:

  "adapter": {
    "resolve": "@slicemachine/adapter-next",
    "options": {
      "jsxExtension": true
    }
  },

Documentation: @slicemachine/adapter-next Technical Reference - Documentation - Prismic

Let us know if it solves your problem.
Xavier

1 Like

Ah, great! Thank you for this. I appreciate it.