-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Use enzyme in tests #1481
Comments
I'll take it. |
I've been working on updating the |
Thanks, please do! It seems that |
Thank you for the counter update! If you’d like, feel free to add enzyme tests to either of these examples:
They currently have no component tests at all. |
Will do. |
Hey I am interested in adding enzyme tests too to the projects with none. May be I'll start with the real world one? |
@fshowalter @borisyankov Please work it out between yourselves 😉 |
@borisyankov real world is all yours 😉 |
@gaearon did you want to keep the tests under /test or colocate them with the source in a tests folder ala React? |
I would keep them under |
Sounds good. On Sun, Mar 6, 2016 at 9:56 AM Dan Abramov notifications@github.com wrote:
|
Quick question here. Is there any codemod for transitioning from |
@tomchentw I don't think so, that would be cool though I didn't see anyone mention |
I would love to see how one tests a Container Component with Enzyme. What is the best way to test that actions are called on certain events, etc. |
…ing_cart_example add shopping cart example tests (for #1481)
@duro you can use sinon.js to 'spy' on a mock store. |
@borisyankov I can't seem to get the component to mount at all. Even using the Here is the test I wrote:
That console.log outputs this: That definitely not what it should be outputting, and lets me test nothing about the component. Here is the component I am trying to test:
|
I would suggest you test a component separately from a store. For example, you can take out the isIOS function in a separate module, and test only it. What you are trying to do, is close to systems or integration testing. |
I am using Karma, and I would like some ability to do some more integration On Tue, Mar 8, 2016 at 2:21 AM, Boris Yankov notifications@github.com
|
…view_example add tree view example tests (for #1481)
Hi @duro , here is what I did if I want to use enzyme - mount into my test import jsdom from 'jsdom';
global.document = jsdom.jsdom('<div id="container"/>');
global.window = document.defaultView;
global.navigator= window.navigator;
// these imports place it after jsdom: https://github.com/airbnb/enzyme/issues/58
import React from 'react';
import test from 'tape';
import { mount } from 'enzyme';
test('<Sample/>', t => {
var Sample = React.createClass({
displayName: 'Sample',
render: function() {
return <div>
<h1 className='cblue'>My Component</h1>
</div>;
}
});
var wrapper= mount(<Sample/>);
var $ = wrapper.find('.cblue');
$.simulate('click');
t.equal( /*..test uquality..*/ );
t.end();
}); |
@wharsojo this still doesn't get me there. I'm trying test react-redux connected containers. |
@gaearon do you want tests for the async example too? |
@fshowalter Yes! |
@gaearon The root reducer in real-world example does export only the combineReducers output. |
@fshowalter @gaearon Why if I add
|
|
@gaearon Thanks :) How could I integrate the store? I think is a best test rather than check a function is called. |
are there any other examples that you were looking to have tests added for? |
I have written tests for Real-World example. Will do a PR soon. |
Given that we've since switched over to Jest and it has first-class support for snapshots from react-test-renderer, I'm going to close this one out. I'll open up a new issue to track moving to react-test-renderer instead and to add some snapshot tests into the mix. |
We should start using enzyme in component tests. It is great and the community seems to have converged on it. We should migrate all our existing tests from
ReactTestUtils
toenzyme
, and use it for any new component tests.I don’t plan to work on this, but if you’d like, please leave a comment stating your intention, and then send a PR when you have something to show so we keep a conversation. If you feel you don’t have the time, don’t worry—just let us know so another person can pick up the task.
Help wanted 😉
The text was updated successfully, but these errors were encountered: