react icon indicating copy to clipboard operation
react copied to clipboard

Add ReactTestUtils to react-tools (main.js) and document it

Open petehunt opened this issue 13 years ago • 11 comments

petehunt avatar Nov 18 '13 09:11 petehunt

:thumbsup:

zpao avatar Nov 18 '13 20:11 zpao

:+1:

plaxdan avatar Nov 20 '13 23:11 plaxdan

:+1: With React's recent increase in popularity, an easy testing story is going to be more and more in demand

thomasboyt avatar Jan 03 '14 21:01 thomasboyt

In fact, would adding a react-with-test-utils.js be fine? It'd just be a version of react-with-addons.js with test utils included, specifically for using in your test runner.

thomasboyt avatar Jan 03 '14 21:01 thomasboyt

I'll take it. I especially want to explain the new ReactTestUtils.mockComponent method: https://github.com/facebook/react/blob/1ee7f8131c1702e3584bbe51d94b503089b8f3bf/src/test/ReactTestUtils.js#L195-L220

benjamn avatar Jan 03 '14 21:01 benjamn

fwiw, here's my take on what I mentioned: https://github.com/thomasboyt/react/commit/01d53c9c074b3d1d0d796edb2819205d24449655

thomasboyt avatar Jan 03 '14 21:01 thomasboyt

Relevant: https://github.com/facebook/react/pull/745

petehunt avatar Jan 03 '14 21:01 petehunt

For anybody running across this issue, @spicyj pointed me at http://myshareoftech.com/2013/12/unit-testing-react-dot-js-with-jasmine-and-karma.html , which includes information for shipping a vendored version of react with test utils, but also uses constructs like

expect(label.refs.p).toBeDefined();
expect(label.refs.p.props.children).toBe("Some Text We Need for Test")

to inspect react component state, which was the necessary piece for me.

rcs avatar Jan 14 '14 07:01 rcs

I have written a library called jasmine-react which I use to test react components: https://github.com/tommyh/jasmine-react.

it allows you todo things like:

  • spyOn methods for a react component
  • stub children components to isolate your tests to just the "component under test"
  • unmounting any component afterEach test
  • setting a class displayName which makes validating error messages easier

repost of info I put in reactjs freenode: in the long run, I might try to merge some of my features into https://github.com/facebook/react/blob/master/src/test/ReactTestUtils.js and https://github.com/facebook/react/issues/560. but for right now, jasmine-react works out of the box w/ no custom grunt build needed

tommyh avatar Jan 14 '14 18:01 tommyh

:+1:

SanderSpies avatar Jan 15 '14 15:01 SanderSpies

This was done

petehunt avatar Apr 03 '14 08:04 petehunt