I can't get a basic test working with react-test-utils and Redux as shown below.
import React from 'react'
import { Provider } from 'react-redux'
import { combineReducers } from 'redux'
import { configureStore } from '@reduxjs/toolkit'
import { render } from '@testing-library/react'
it('renders welcome message', () => {
const store = configureStore({
reducer: combineReducers({}),
})
console.log(store)
const { getByText } = render(
<Provider store={store}>
<h1>hi</h1>
</Provider>
)
expect(getByText('hi')).toBeInTheDocument()
})
it fails with this error
Provider(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
14 | console.log(store)
15 |
> 16 | const { getByText } = render(
| ^
17 | <Provider store={store}>
18 | <h1>hi</h1>
19 | </Provider>
at reconcileChildFibers (node_modules/react-dom/cjs/react-dom.development.js:14348:23)
at reconcileChildren (node_modules/react-dom/cjs/react-dom.development.js:16762:28)
at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17542:5)
at beginWork (node_modules/react-dom/cjs/react-dom.development.js:18596:16)
at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:188:14)
...
But if comment out the <Provider> like shown below then test passes
it('renders welcome message', () => {
const store = configureStore({
reducer: combineReducers({}),
})
console.log(store)
const { getByText } = render(
// <Provider store={store}>
<h1>hi</h1>
// </Provider>
)
expect(getByText('hi')).toBeInTheDocument()
})
