Reproduce:
Test suite failed to run
ReferenceError: WebSocket is not defined
5 | Reactotron.configure({ name: 'Wanderlust App' })
6 | .useReactNative({})
> 7 | .connect();
| ^
8 | }
9 |
at createSocket (node_modules/reactotron-react-native/dist/index.js:1:14125)
at a.value (node_modules/reactotron-core-client/dist/index.js:1:9009)
at Object.connect (src/config/ReactotronConfig.ts:7:10)
at Object.<anonymous> (App.tsx:29:1)
console.error node_modules/fbjs/lib/warning.js:30
You can see the files:
ReactotronConfig.ts file here
App.ts file here
App-tests.ts file here
@rmevans9 I believe you fixed this a while back... Are you aware of this?
@NelsonPRSousa Nope, this is not something I am familiar with. I would suspect that all that is happening is reactotron-react-native expects that WebSocket is something that is available (which is a safe assumption in react-native) but it is unavailable in a test environment. I would say the quickest path to success here is to provide a mock implementation of WebSocket
Thanks
@NelsonPRSousa Do you have the sample WebSocket mock implementation?
No @mthuong, we are no longer using reactotron
@mthuong
__mocks__/globalMock.js:
jest.mock('global', () => ({
...global,
WebSocket: function WebSocket() {},
}));
and configure your jest
`
"setupFilesAfterEnv": [
"<rootDir>/__mocks__/globalMock.js"
]
Most helpful comment
@mthuong
__mocks__/globalMock.js:and configure your jest
`
"setupFilesAfterEnv": [ "<rootDir>/__mocks__/globalMock.js" ]