Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upReactotron becomes undefined when mocking with jest #1120
Labels
Comments
|
We probably should do some good docs here. I will see if I can get something together soon. |
|
i'm having the same trouble here. :/ |
|
Same issue, any workaround? |
|
Try: const reactotron = {
configure: () => reactotron,
useReactNative: () => reactotron,
use: () => reactotron,
connect: () => reactotron,
clear: () => reactotron,
createEnhancer: () => reactotron
};
jest.mock("reactotron-react-native", () => reactotron); |
|
What worked for me: // ReactotronConfig.js
import Reactotron, { asyncStorage } from 'reactotron-react-native';
import { AsyncStorage } from 'react-native';
import { reactotronRedux } from 'reactotron-redux';
const IP_ADDRESS = '192.168.15.88';
const reactotron = Reactotron.setAsyncStorageHandler(AsyncStorage)
.configure({ host: IP_ADDRESS })
.useReactNative({})
.use(asyncStorage())
.use(reactotronRedux())
.connect();
export default reactotron;//__mocks__/reactotron-react-native.js
/* eslint-disable no-undef */
export default {
setAsyncStorageHandler: () => ({
configure: () => ({
useReactNative: () => ({
use: () => ({
use: () => ({
connect: () => ({
createEnhancer: jest.fn(),
}),
}),
}),
}),
}),
}),
};
export const asyncStorage = jest.fn();Important: I had to mock the reactotron object in the same order I was calling in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


I have issues to get Reactotron working in my jest react-native test environment.

Before running a test I simply do
jest.mock("reactotron-react-native");, but then I receive an error statingTypeError: Cannot read property 'useReactNative' of undefinedUnfortunately, I don't find any recommendation in your docs for setting reactotron up for testing.
Really appreciate your help in advance! :)