Search code examples
react-nativeraygun

ReferenceError: raygunUtilityFactory is not defined


I am trying to implement raygun for a react-native app. I am running into problems with jest and I am not sure of the best approach given the window does not exist. In my package.json I have already added the following:

"globals": {
  "window": {}
}

I get the following error though and I am unable to resolve it as of yet:

ReferenceError: raygunUtilityFactory is not defined

This is a very basic implementation as per the docs: https://raygun.com/docs/languages/javascript#reactnative

I presume this is something with jest but having searched on github, here and google I still have not been able to resolve this.


Solution

  • Raygun4JS does not currently work correctly in a non-browser environment. Your best bet would be to not include the Raygun4JS code inside of your test environment (which is what we do at Raygun) but that is a bit more complicated using the UMD module from NPM (we use the snippet approach to inject it dynamically).

    I think the problem stems from window not being considered the global object in Jest vs the browser, we have an indirect call to the window object to call the raygunUtilityFactory. Are you using the jsdom test environment? We also have the same window definition in our jestconfig.json and export some variables onto window in our setupframework.js file that are accessed indirectly through the global object and it appears to work correctly.