Getting error while running test cases in react native

45 views Asked by At

I'm getting following issue while running test cases in react native

● Login › renders correctly

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

  20 |   const mockStore = configureStore(middlewares);
  21 |   const store = mockStore(options?.store ?? setupStore(options?.initialState));
> 22 |   const queries = render(<Provider store={store}>{ui}</Provider>);
     |                         ^
  23 |   return { ...queries, store };
  24 | };

Login-test.js

import React from 'react';
import { fireEvent, cleanup, render } from '@testing-library/react-native';
import Login from '../src/screens/login';
import { renderWithRedux } from '../src/utils/test-utils';

afterEach(cleanup);

const initialState = {
  login: { userData: null, token: null, refreshToken: null },
};

describe('Login', () => {
  it('renders correctly', () => {
    const { toJSON } = renderWithRedux(<Login />, { initialState });
    expect(toJSON()).toMatchSnapshot();
  });

});

test-utils.js

import React from 'react';
import { Provider } from 'react-redux';
import { render } from '@testing-library/react-native';
import { setupStore } from '../redux/app/store';
import configureStore from 'redux-mock-store';
export const renderWithRedux = (ui, options) => {
  const middlewares = [];
  const mockStore = configureStore(middlewares);
  const store = mockStore(options?.store ?? setupStore(options?.initialState));
  const queries = render(<Provider store={store}>{ui}</Provider>);
  return { ...queries, store };
};

please let me know anything i was missing to add and another thing is that it was issue only for redux connected components.

0

There are 0 answers