Skip to content
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

Update documentation with issues using react-test-renderer #250

Closed
mrchief opened this issue Jun 19, 2018 · 4 comments
Closed

Update documentation with issues using react-test-renderer #250

mrchief opened this issue Jun 19, 2018 · 4 comments

Comments

@mrchief
Copy link

mrchief commented Jun 19, 2018

Creating this issue as per our discussion on gitter.

react-test-renderer doesn't support refs based components for testing. See:

facebook/react/issues/9244
facebook/jest/issues/1805
facebook/jest/issues/5462

The workarounds are:

Mock 3rd party components

E.g.

jest.mock('rmwc/TopAppBar/TopAppBar', () => {
  return (props) => <div>{props.children}</div>;
})

Use something like createNodeMock

See https://reactjs.org/docs/test-renderer.html#ideas (source)

Use ReactDOM or Enzyme

See facebook/jest/issues/5462#issuecomment-363532494

@mrchief
Copy link
Author

mrchief commented Jun 19, 2018

Enzmye based test:

import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'

describe('<Header />', () => {
  it('renders', () => {
    const props = {
      siteTitle: 'Test Site Title'
    }

    const wrapper = shallow(<Header {...props} />)

    expect(toJson(wrapper)).toMatchSnapshot()  // optional. only needed for snapshot based testing 
  })
})

@jamesmfriedman
Copy link
Collaborator

@mrchief does the shallow rendering from the Enzyme based test work?

@mrchief
Copy link
Author

mrchief commented Jun 20, 2018

Yes, no issues with Enzyme. I'm still using the polyfill though. Let me know if you want me to try without the polyfill.

@jamesmfriedman
Copy link
Collaborator

Updated the docs accordingly, will be released with 1.8

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

No branches or pull requests

2 participants