Currently, I am facing an issue with my project where a method defined in the script tag of the index.html
file is causing Jest to fail during execution.
index.html
<script>
var getCookie = function(cookieVal) { return cookieVal; }
</script>
In order to address this problem, I have attempted to define the 'getCookie' variable within Jest globals as follows:
package.json
"jest": {
"globals": {
"getCookie": "someString"
}
}
Although this successfully defines getCookie
, running tests results in the following error message:
Error in data(): "TypeError: getCookie is not a function"
While this error is expected, I am uncertain about how to define it as a function in the globals
object.
What would be the best approach for mocking my getCookie
function in Jest?