Q:

How to put functions in jest globals? 

I am setting up jest and it is not finding window. I18n.t() because it's defined by sprockets (ruby on rails, independent of webpack).  So I'd like to mock that method.  Here is the error:
 FAIL  spec/javascript/sanity_test.js
  ● Test suite failed to run

    TypeError: Cannot read property 't' of undefined

      24 |
      25 | export const newOrderPreferenceObject = {
    > 26 |   label: window. I18n.t("some.path.in.localization"), default_value: "",

in package.json I can do this:
 "jest": {
    "testEnvironment": "jsdom",
    "globals": { 
      "window": {
        "I18n": { "t": {} }
      }
    },

I change testEnvironment from jsdom to node, as well. 
However, t() must be a function, not a data structure.  So how do I put a function in window in jest test? 

A:

I don't know the circumstances of your project but here's how I setup and mock global objects in my projects. 
I create a setupTests.js in the root src directory and mock them there. 
setupTests.js
window. I18n = {
  t: jest.fn(),
}

https://create-react-app.dev/docs/running-tests/#srcsetuptestsjs-1

