With the simplest component, ReactJS Jest does not report full testing. How to get approval and branch to show 100%.
Jest currently shows 90.48% statements, 58.06% branch . Run using jest --coverage .
MyThing.js
import React from 'react'; export default class MyThing extends React.Component { render() { return ( <div> Stuff </div> ); } }
MyThing-test.js
// __tests__/MyThing-test.js jest.unmock('../app/views/static/MyThing'); import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; import MyThing from '../app/views/static/MyThing'; describe('MyThing', () => { const instance = TestUtils.renderIntoDocument( <MyThing /> ); it('gets rendered', () => { expect( TestUtils.isCompositeComponent(instance) ).toBeTruthy(); }); it('is not DOM component', () => { // checks if is a standard DOM element, ie <div> expect( TestUtils.isDOMComponent(instance) ).not.toEqual(true); }); it('isElementOfType is React element', () => { expect( TestUtils.isElementOfType(<MyThing />, MyThing) ).toEqual(true); }); it('render()', () => { const retVal = instance.render(); expect( retVal.type ).toEqual("div"); }); });
source share