I have a line of code that looks something like this:
return someObj.getSomething(param).doSomethingElse().key.anotherKey
All of my jest unit tests pass.
In order to be a bit safer, I added optional chaining to that line so now it looks like:
return someObj?.getSomething(param)?.doSomethingElse()?.key?.anotherKey
As soon as I do that, the corresponding test suite results in errors:
Test suite failed to run
TypeError: Property property of OptionalMemberExpression expected node to be of a type ["Identifier"] but instead got "CallExpression"
at validate (node_modules/@babel/types/lib/definitions/utils.js:132:11)
at Object.validator [as validate] (node_modules/@babel/types/lib/definitions/core.js:1451:11)
at validateField (node_modules/@babel/types/lib/validators/validate.js:24:9)
at Object.validate (node_modules/@babel/types/lib/validators/validate.js:17:3)
at NodePath._replaceWith (node_modules/@babel/traverse/lib/path/replacement.js:179:7)
at NodePath.replaceWith (node_modules/@babel/traverse/lib/path/replacement.js:161:8)
at RewireState.Identifier (node_modules/babel-plugin-rewire/lib/babel-plugin-rewire.js:187:10)
at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:92:31)
The optional chaining plugin is added in my package.json
file as so:
"dependencies" : {
"@babel/plugin-proposal-optional-chaining": 7.14.5
}
and in my babel.config.js
file as well.
Any help would be greatly appreciated.