mercredi 27 avril 2016

Unit test cannot find module components in AppBar 'iconElementRight'

I'm testing a material-ui component that has AppBar with its iconElementRight containing a few components that I created.

While I can run this fine in my browser, when I try to renderIntoDocument in my unit test, It complains that it cannot find the child components. "Module not found: Error: Cannot resolve 'file' or 'directory' ./MyCustomComponent1"

My appbar JSX

import React, {PropTypes} from 'react'
/** material-ui **/
import AppBar from 'material-ui/AppBar'
/** components **/
import MyCustomComponent1 from './MyCustomComponent1';
import MyCustomComponent2 from './MyCustomComponent2';
export default class MyAppBar extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        let me = this;
        return (<AppBar
                    title="  "
                    iconElementRight={
                          <div>
                            <MyCustomComponent1/>
                            <MyCustomComponent2/>
                          </div>
                    }>
                </AppBar>);
    }
}

My unit test:

import React from 'react'
import TestUtils from 'react-addons-test-utils';
import chai from 'chai'
import MyAppBar from './MyAppBar.jsx';
var should = chai.should(),
    expect = chai.expect;
describe('<MyAppBar/>', () => {
    it('should pass', () => {
        var domElement = TestUtils.renderIntoDocument(<MyAppBar/>);
        expect(true).to.equal(true);
    });
});

Aucun commentaire:

Enregistrer un commentaire