Using Mocha, Karma, and React test tools to test the following simple function:
renderTodoCount() {
const { incompleteCount } = this.props;
const itemWord = incompleteCount === 1 ? 'item' : 'items';
return (
<span className='todo-count'>
<strong>{incompleteCount || 'No'}</strong> {itemWord} left
</span>
);
}
I'm splitting the test cases up into three cases: 1. incompleteCount=0, 2. incompleteCount=1, 3. incompleteCount=2.
In the first case, I would expect the following output (more or less):
<span className='todo-count'>
<strong>No</strong> items left
</span>
and would test against that. What I am actually seeing(from dump()) is:
<span class="todo-count" data-reactid=".0.0">
<strong data-reactid=".0.0.0">No</strong><span data-reactid=".0.0.1"></span><span data-reactid=".0.0.2">items</span><span data-reactid=".0.0.3"> left</span>
</span>
Is there a good way to test the value of the text inside of the main span? I'm looking for something equivalent to .val() or .text() in jQuery.
TestUtils.findRenderedDOMComponentWithClass('todo-count').getDOMNode().textContentconst itemWord = incompleteCount !== 0 ? 'item' : 'items';