Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jestjs

vite

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.

like image 538
user3612643 Avatar asked Sep 05 '25 03:09

user3612643


1 Answers

I added the following to moduleNameMapper it worked.

"moduleNameMapper": {
  ".*\\.txt\\?raw": "jest-raw-loader"
}
like image 122
Richard Fernandez Avatar answered Sep 07 '25 21:09

Richard Fernandez