Assuming the following 2 components
var Level2 = React.createClass({
render: function () {
return React.createElement('div');
}
});
var Level1 = React.createClass({
render: function () {
return React.createElement(Level2);
}
});
and the following helper for shallow rendering testing in Jasmine
var TestUtils = React.addons.TestUtils;
var shallowRender = function(element, props, children) {
var ShallowRenderer = TestUtils.createRenderer();
ShallowRenderer.render(React.createElement(element, props, children));
return ShallowRenderer.getRenderOutput();
};
The second test does not behave as I expect:
describe ('test rendered output', function (){
it('level 2 should render a div component', function() {
l2 = shallowRender(Level2);
expect(l2.type).toBe('div') // this test PASSES
});
it('level 1 should render a level 2 component', function() {
l1 = shallowRender(Level1);
// this test FAILS with the following message 'Expected Function to be 'Level2'
expect(l1.type).toBe('Level2')
})
});
Any idea why the second test fails ?