Tell jest to handle Vite's "?raw" syntax

Viewed 112

Vite allows to import files as raw strings using

import foo from "foo.txt?raw"

However, jest complains that it cannot find the file. I found the jest-raw-loader, but I don't know how to tell it to apply raw loading to the "?raw" syntax.

1 Answers

I added the following to moduleNameMapper it worked.

"moduleNameMapper": {
  ".*\\.txt\\?raw": "jest-raw-loader"
}
Related