Search code examples
reactjsreduxecmascript-6react-testing-librarytesting-library

What does this part of the Redux document mean?


I'm using the Redux-tool kit to set it up. We are now using @testing-library/react to set up testing-related settings. I got a question while looking at the official document.

// test-utils.js
import React from 'react'
import { render as rtlRender } from '@testing-library/react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
// Import your own reducer
import reducer from '../reducer'

function render(
  ui,
  {
    initialState,
    store = createStore(reducer, initialState),
    ...renderOptions
  } = {}
) {
  function Wrapper({ children }) {
    return <Provider store={store}>{children}</Provider>
  }
  return rtlRender(ui, { wrapper: Wrapper, ...renderOptions })
}

// re-export everything
export * from '@testing-library/react'
// override render method
export { render }

What function does this part have in the code part above?

// re-export everything
export * from '@testing-library/react'
// override render method
export { render }


Solution

  • I don't know this library, but export * from '@testing-library/react' just means that anything you can import from @testing-library/react, you can now import directly from this file, test-utils.js.

    I guess that they found it convenient to have a way to access just the react testing modules in one place, with the render method overwritten with their own custom version defined above.