Skip to content

Docs: alt import/export pattern #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

alexkrolick
Copy link
Collaborator

@alexkrolick alexkrolick commented Sep 8, 2018

What:

Why:

How:

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

fixes #169

@yashhy
Copy link

yashhy commented Sep 10, 2018

Hmm...was trying something like below and then saw ur PR.

import { render as reactTestingRender } from 'react-testing-library';
import TestWrapper from './TestWrapper';
import React from 'react';

const render = (node, ...options) => {
  return reactTestingRender(
    <TestWrapper>{node}</TestWrapper>,
    ...options
  )
};

export * from 'react-testing-library';
export { render };

But still it throws the error,

TypeError: Cannot set property render of [object Object] which has only a getter

@alexkrolick did i miss something?

@kentcdodds
Copy link
Member

I wonder if it has to do with Babel configuration...

@kentcdodds
Copy link
Member

Let's go with that! Would you like to make a pull request to add a note about that?

@christian314159
Copy link

Getting the same TypeError, what in the Babel setting is causing this? Going with calling it renderWithTheme for now to work around the issue for now though.

@kentcdodds
Copy link
Member

I think if folks use Babel 7 they should be good with what we have documented already. Maybe we should add a note about that instead...

@kentcdodds kentcdodds closed this Sep 18, 2018
@alexkrolick alexkrolick deleted the patch-1 branch December 9, 2018 03:59
lucbpz pushed a commit to lucbpz/react-testing-library that referenced this pull request Jul 26, 2020
@szokrika
Copy link

szokrika commented Oct 3, 2023

Does anyone else experienced this error message again?
Running latest Babel deps, I see the same error...

@MatanBobi
Copy link
Member

@szokrika Can you please share a repro so we'll be able to help?

@szokrika
Copy link

szokrika commented Oct 13, 2023

@MatanBobi thanks for your help! Let me know if you need the babel/jest config as well

import thunk from 'redux-thunk'
import PropTypes from 'prop-types'
import { Provider } from 'react-redux'
import { applyMiddleware, combineReducers, createStore } from 'redux'
import compose from 'app/utils/compose'
import reducers from 'app/reducers/index'
import { userEvent } from '@testing-library/user-event'
import { render as rtlRender } from '@testing-library/react'
import { DisclaimerProvider } from '@customPackage/react-component-library'

function createMockStore(initialState = {}) {
  const rootReducer = combineReducers(reducers)
  const middlewares = thunk
  const create = compose(applyMiddleware(middlewares))(createStore)
  return create(rootReducer, initialState)
}

function customRender(
  ui,
  { initialState, store = createMockStore(initialState), ...options } = {}
) {
  function Wrapper({ children }) {
    return (
      <Provider store={store}>
        <DisclaimerProvider>{children}</DisclaimerProvider>
      </Provider>
    )
  }
  Wrapper.propTypes = {
    children: PropTypes.node
  }

  return rtlRender(ui, { wrapper: Wrapper, ...options })
}

export * from '@testing-library/react'

export { customRender as render, userEvent }
    TypeError: Cannot read properties of undefined (reading 'replace')

      34 |
    > 35 |   return rtlRender(ui, { wrapper: Wrapper, ...options })
         |                   ^
      36 | }
      37 | // re-export everything
      38 | export * from '@testing-library/react'

@MatanBobi
Copy link
Member

@szokrika Unfortunately, that's not enough. If you can please open a new issue with a shareable reproduction (either codesandbox or github repo) it will help us investigate and help :)

@szokrika
Copy link

@MatanBobi
Nevermind, I was able to work around the issue, by refactoring/fixing some of my components. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixing custom render with all other exports gives error
6 participants