1 year ago

#279246

test-img

chewie

React testing library with redux-form issue

Having an issue trying to test redux-forms components. I keep getting an error FormSection must be inside a component decorated with reduxForm() Here is test code.

import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { reducer as formReducer } from 'redux-form';
import { render, screen, cleanup, fireEvent} from '@testing-library/react'
import "@testing-library/jest-dom";
import ContactInformation from '../components/FormSections/ContactInformation'


// Create a reducer that includes the form reducer from redux-form
const rootReducer = combineReducers({
  form: formReducer,
});

const store = createStore(rootReducer);

const renderContactInformation = () => {
  render(
    <Provider store={store}>
      <ContactInformation />
    </Provider>,
  )
}

describe("<ContactInformation />", () => {
  test('it should render fields', () => {
    renderContactInformation()
    const input = screen.getByLabelText("email")
    console.log(input)
        }
      )

})

any thoughts? These seems like it should work but I think I am at a lost or perhaps I just confused my self. Any help will greatly be appreciated.

javascript

reactjs

redux

redux-form

react-testing-library

0 Answers

Your Answer

Accepted video resources