2
I am developing a system in Electron that works well, but when running the tests in Jest I get the following error:
console.error
Error: Uncaught [TypeError: value.replaceAll is not a function]
at reportException (C:\Users\rafae\Desktop\VisualData\pdv\node_modules\jsdom\lib\jsdom\living\helpers\runtime-script-errors.js:62:24)
at innerInvokeEventListeners (C:\Users\rafae\Desktop\VisualData\pdv\node_modules\jsdom\lib\jsdom\living\events\EventTarget-impl.js:333:9)
at invokeEventListeners (C:\Users\rafae\Desktop\VisualData\pdv\node_modules\jsdom\lib\jsdom\living\events\EventTarget-impl.js:274:3)
...
My code is this::
let index = 0;
const value = 'Alguma string';
return value.replaceAll('.', match => index++ === 0 ? match : '');
I am using version 26.0.1 of Jest and 14.5.4 of Node. Electron is version 11.4.7, Chrome 87.0.4280.141.
- Why this problem occurs if on my system is working well?
- How can I fix this in Jest without using
.replace
with Regexp?
Rafael, aren’t the parameters changed? regex/match should come first I think.. see documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
– Ricardo Pontual
The syntax is
const newStr = str.replaceAll(regexp|substr, newSubstr|function)
. In case I usedstr.replaceAll(substr, function)
, wheresubstr
is the string to be replaced by the function. The function replaces all points.
with the exception of the first, so theindex++ === 0
. I didn’t use Regexp.– Rafael Tavares
To those who voted against, please say what is wrong with the question or what can be improved. I sought to put all necessary details without leaving the extensive question :)
– Rafael Tavares