Преобразование кода
Jest выполняет код вашего проекта как JavaScript, но если вы используете синтаксис, который не поддерживается Node. js из коробки (например, JSX, типы из TypeScript, шаблоны Vue и т. д.), то сначала нужно транспилировать ваш код в чистый JavaScript, по аналогии сборки проектов для клиентской части.
Jest supports this via the transform configuration option.
Трансформер - это модуль, который предоставляет метод преобразования исходных файлов. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by Node, you might plug in a code preprocessor that would transpile a future version of JavaScript to a current one.
Jest закэширует результат преобразования, а если исходный файл или параметры конфигурации были изменены, тогда данные в кэше станут недействительными и преобразования будут зап ущены заново.
Конфигурация по умолчанию
Jest ships with one transformer out of the box – babel-jest. It will load your project's Babel configuration and transform any file matching the /\.[jt]sx?$/ RegExp (in other words, any .js, .jsx, .ts or .tsx file). In addition, babel-jest will inject the Babel plugin necessary for mock hoisting talked about in ES Module mocking.
Remember to include the default babel-jest transformer explicitly, if you wish to use it alongside with additional code preprocessors:
"transform": {
"\\.[jt]sx?$": "babel-jest",
"\\.css$": "some-css-transformer",
}