Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeError: Cannot read property 'objects' of undefined Jest

$
0
0

I get this error while running a jest test that has realm object called in it ie in the component. The component that is being tested it a react-native typescript component. Any Idea on how to mock the realm object in the jest?

import 'react-native';import React from 'react';import { Provider } from 'react-redux'; import configureMockStore from 'redux-mock-store';import { mount } from 'enzyme';import renderer from 'react-test-renderer';import SendBird from 'sendbird';import { Actions } from 'react-native-router-flux';import Chat from '../src/pages/chat/chat';import offline from '../src/utils/OfflineNotification';const mockStore = configureMockStore();const store = mockStore({authReducer: {loggedInUserDetails: {  username: 'Test user',  attributes: { email: 'test@fissionlabs.com', 'custom-name': 'asd123' }, },},companyProfile: {companiesListBuffer: [],currentDisplayedCompany: {  startup: {    name: '',    keywords: '',    labels: '',    deadline: '',    elevator_pitch: '',    total_addressable_market: '',    notable_customers: '',    founding_team: '',    lead_investor: '',    interested_investors: '',    round_deadline: '',    pitch_deck: '',    metrics: '',    commited: '',    round: '',    questions: '',    stage: '',    logo: '',  }, },},profileData: { profileData: { name: 'Test profile' },},});jest.useFakeTimers();jest.mock('sendbird');jest.mock('react-native-popup-menu');jest.mock('@react-native-community/async-storage', () => {return {getItem: jest.fn(() => Promise.resolve()),};});jest.mock('react-native-image-picker', () => {return {showImagePicker: jest.fn(() => Promise.resolve()),};});jest.mock('react-native-device-info', () => {return {hasNotch: jest.fn(),};});jest.mock('react-native-safe-area', () => {return {getSafeAreaInsetsForRootView: jest.fn(() => Promise.resolve()),};});describe('Test Connectors', () => {let wrapper = null;let instance = null;const props = { saveCurrentCompanyAction: jest.fn(), getOnPress: jest.fn(), closeChat: jest.fn(), direction: 'left', chatInfoData: {  data: { startupId: 'wed23242' },  customType: 'Custom', }, continueMessage: false, previousMessage: {  value: {    __sender: {      userId: 123,    },  },}, nextMessage: {  value: {    __sender: {      userId: 123,    },  }, }, message: {  _sender: {    metaData: {      role: 'founder',    },    userId: 1,  },  data: '', }, chatInfo: {  userId: 22,  accessToken: '',  chatId: 'chat01', }, messageStatus: 'delivered',};beforeEach(() => {console.error = () => {};console.warn = () => {};jest.mock('react-redux', () => {  return {    connect: (mapStateToProps, mapDispatchToProps) => (ReactComponent) =>  ({      mapStateToProps,      mapDispatchToProps,      ReactComponent,    }),    Provider: ({ children }) => children,  }; }); wrapper = mount(<Provider store={store}><Chat {...props} /></Provider>, )  .childAt(0)  .childAt(0); instance = wrapper.instance(); }); it.only('should render successfully', () => {  expect(wrapper).toBeTruthy(); });

Here The wrapper is always undefined. Is there Any way that I can mock realm as I have mocked all the other imports? Thanks


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>