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

Error: Expected a ReactElement, got number #8

Closed
fzaninotto opened this issue Nov 6, 2015 · 4 comments
Closed

Error: Expected a ReactElement, got number #8

fzaninotto opened this issue Nov 6, 2015 · 4 comments

Comments

@fzaninotto
Copy link

Unit test:

import expect from 'expect';
import expectJSX from 'expect-jsx';
import React from 'react';

import { createRenderer } from 'react-addons-test-utils';

expect.extend(expectJSX);

describe(`toEqualJSX`, () => {
    it('should accept JSX with numbers', () => {
        const MyTable = () => (
            <span>{123}</span>
        )
        const shallowRenderer = createRenderer();
        shallowRenderer.render(<MyTable/>);
        const component = shallowRenderer.getRenderOutput();
        expect(component).toEqualJSX(<span>123</span>);
    });
});

Output:

  1) toEqualJSX should accept JSX with numbers:
     Error: react-element-to-jsx-string: Expected a ReactElement, got `number`
      at toJSXString (node_modules/expect-jsx/node_modules/react-element-to-jsx-string/index-dist.js:51:11)
      at node_modules/expect-jsx/node_modules/react-element-to-jsx-string/index-dist.js:179:12
      at Array.map (native)
      at toJSXString (node_modules/expect-jsx/node_modules/react-element-to-jsx-string/index-dist.js:104:97)
      at reactElementToJSXString (node_modules/expect-jsx/node_modules/react-element-to-jsx-string/index-dist.js:37:10)
      at Expectation.toEqualJSX (node_modules/expect-jsx/index-dist.js:27:78)
      at Context.<anonymous> (app/frontend/test/unit/components/Assessment/Test.spec.js:17:27)

I managed to fix it by adding another condition on type 'number' on

if (typeof ReactElement === 'string') {

@vvo
Copy link
Contributor

vvo commented Nov 7, 2015

Well @fzaninotto it all look very good: you have the unit test and the fix, shoot me a PR! Or I will do the change but really you already did all the work :)

@fzaninotto
Copy link
Author

I was kinda hoping I wouldn't have to clone your repo...

@vvo
Copy link
Contributor

vvo commented Nov 8, 2015

Wfm. I do think the effort you put in writing the issue was longer than just submitting a PR thought :-D

@vvo
Copy link
Contributor

vvo commented Nov 8, 2015

fixed and released expect-jsx@2.1.1

npm install expect-jsx@2.1.1 --save-dev

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