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

TestUtils cannot render stateless function components #5901

Closed
ibrown-gaikai opened this issue Jan 21, 2016 · 4 comments
Closed

TestUtils cannot render stateless function components #5901

ibrown-gaikai opened this issue Jan 21, 2016 · 4 comments

Comments

@ibrown-gaikai
Copy link

I'm using react 14.3, babel 6.0.15 and react test utils addon 0.14.6 . Jasmine 2.3 is my testing framework of choice.

It seems as though any stateless function component cannot be tested by TestUtils.renderIntoComponent or TestUtils.createRenderer().render(). Either returns null when rendering the function component.

Test with any stateless function component and it should yield the same result.

Component:

import React from 'react';

const User = ({name, age}) => ( return <div>{name}, {age}</div> );

module.exports = User;

Test:

expect(TestUtils.renderIntoDocument(<User name={"bob"} age={20} />)).toBeTruthy();

Error:

Expected null to be truthy.

@jimfb
Copy link
Contributor

jimfb commented Jan 21, 2016

Duplicate of #5455

@jimfb jimfb closed this as completed Jan 21, 2016
@antgonzales
Copy link

@jimfb I'm not sure this is necessarily a duplicate. This is specific to the TestUtils render, not necessarily refs at the end of that ticket chain you mentioned above. I'm currently having this issue with Phantom + Mocha.

@thealjey
Copy link

@antgonzales did you manage to overcome this problem somehow?

@antgonzales
Copy link

@thealjey I moved over to Jest/JSDOM/Enzyme, I bet this issue isn't a problem in a Jest/JSDOM environment. Happy to give it a test if you're seeing this issue in that environment or a Mocha/JSDOM environment.

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

4 participants