1

I'm writing tests for my react application. But when I try to render a nested component, then I got the error TitleBar is not defined and the test fails.

jest.dontMock('FUW.js');
jest.dontMock('TitleBar.js');

var React = require('react/addons');
var TitleBar = require('../js/components/TitleBar.js');
var FirstUseWindow = require('../js/components/windows/FirstUseWindow.js');
var TestUtils = React.addons.TestUtils;


describe('First use wizard', function(){
    afterEach(function(done){//cleanup the DOM
        React.unmountComponentAtNode(document.body);
        setTimeout(done);
    });

    var FirstUseWindowElement = TestUtils.renderIntoDocument(
        <div>
        <FirstUseWindow />
        </div>
    );
});

The FirstUseWindow contains a TitleBar element which causes the error.

FUW.js

if (React === undefined) {
    var React = require('react/addons');
}

var FirstUseWindow = React.createClass({
    firstUseComplete:function(){
    },    
    render:function(){
        return(
            <div>
                <TitleBar text="tested" />

            </div>
        );
    }
});

if (module !== undefined) {
    module.exports = FirstUseWindow;
}

TitleBar.js

if (React === undefined) {
    var React = require('react/addons');
}

var TitleBar = React.createClass({
    render:function(){
        return(
            <header className="bar bar-nav">
                <h1 className="title">{this.props.text}</h1>
            </header>
        );
    }
});

if (module != undefined) {
    module.exports = TitleBar;
}

1 Answer 1

2

Title bar is undefined because its not being required in fuw.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.