thrown: undefined after using middleware in jest

Viewed 967

I'm using jest to test react testing with router and I used applyMiddleware to deal with async function in react code I'm getting below error after using middleware after npm run test and the test fails Test Code (Jest):

import React from "react";

import Results from '../Results'

import { render,cleanup} from '@testing-library/react';

import { createStore, applyMiddleware} from 'redux'

import { Provider } from 'react-redux'

import { BrowserRouter as Router, Route } from 'react-router-dom';

import "@testing-library/jest-dom"

import "@testing-library/jest-dom/extend-expect";

import thunk from 'redux-thunk';

function reducer(state, action) {

   switch (action) {

      default:
        return state

    }

}

function renderWithRedux(

    component,

    { initialState, store = createStore(reducer, initialState, applyMiddleware(thunk)) } = {}

    ) {

    return {

        ...render(<Provider store={store}><Router>{component}</Router></Provider>)


    }
}


afterEach(cleanup);

test("Testing result",async () => {

    const dispatch = jest.fn();

    const { getByTestId, getByText } = renderWithRedux(<Results dispatch={dispatch}/>);

});

After using the middlewaares I'm getting

Error received:

thrown: undefined

 test("Testing result",() => { .....
 ^

 Test Suites: 1 failed, 1 total
 Tests:       1 failed, 1 total
0 Answers
Related