Jest-babel createTransformer Error: customJSTransformer.includes is not a function
See original GitHub issue🐛 Bug Report
When using the transform configuration, for transpiling my JS using Babel, I get an error from jest stating:
TypeError: customJSTransformer.includes is not a function
This error occurs, since the setupBabelJest
assumes, that the JS transform property is an array:
https://github.com/facebook/jest/blob/master/packages/jest-config/src/normalize.js#L138
But the value returned by babelJest.createTransformer() is an Object with implements the Jest Transformer.
I’m not shure how a fix might be possible, otherwhise I would include a PR.
Maybe the if chain could first check, if it an Object and then else if ()
check if it’s an array afterwards.
To Reproduce
jest.config.js:
const babelJest = require("babel-jest");
module.exports = {
transform: {
"^.+\\.jsx?$": babelJest.createTransformer({
presets: [
[
require.resolve("babel-preset-env"),
{
targets: {
node: "10"
}
}
]
]
})
}
};
command:
jest
Expected behavior
The transformer should be appended correctly and without error to the jest Config
Link to repl or repo (highly encouraged)
https://github.com/NicolaiSchmid/jest-error
- clone
yarn
yarn test
Run npx envinfo --preset jest
Paste the results here:
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: x64 Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz
Binaries:
Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node
Yarn: 1.9.4 - /usr/bin/yarn
npm: 6.3.0 - ~/.nvm/versions/node/v9.4.0/bin/npm
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8
Top GitHub Comments
We do not have support for creating a transformer that way. It needs to be a separate file, then you can do
require.resolve
on it.I do think supporting it would be good though, so keeping this open as a feature request
I have a similar error but with
Array.reverse is not a function
I tried with a custom transform, and with thebabel.config.js
on the root of the package (sub-package on monorepo) and didn’t work, I also tested passing directly the configuration options to the transformer and didn’t work.