Add toBeTextComponentWithValue to reactComponentExpect

This was previously possible by looking at renderedChildren and props
but this feels better.
This commit is contained in:
Paul O’Shannessy
2014-12-14 14:12:29 -08:00
parent 6bb77b5d4d
commit c9fb5b258e
3 changed files with 52 additions and 2 deletions
@@ -70,7 +70,7 @@ var expectChildren = function(d, children) {
if (typeof child === 'string') {
reactComponentExpect(d)
.expectRenderedChildAt(i)
.toBeTextComponent();
.toBeTextComponentWithValue(child);
textNode = d.getDOMNode().childNodes[i].firstChild;
@@ -0,0 +1,49 @@
/**
* Copyright 2013-2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails react-core
*/
"use strict";
var React;
var ReactTestUtils;
var reactComponentExpect;
var mocks;
var warn;
describe('reactComponentExpect', function() {
beforeEach(function() {
React = require('React');
ReactTestUtils = require('ReactTestUtils');
reactComponentExpect = require('reactComponentExpect');
});
it('should detect text components', function() {
var SomeComponent = React.createClass({
render: function() {
return (
<div>
<div>This is a div</div>
{'This is text'}
</div>
);
}
});
var component = ReactTestUtils.renderIntoDocument(<SomeComponent />);
reactComponentExpect(component)
.expectRenderedChild()
.expectRenderedChildAt(1)
.toBeTextComponentWithValue('This is text');
});
});
+2 -1
View File
@@ -139,9 +139,10 @@ assign(reactComponentExpectInternal.prototype, {
return this;
},
toBeTextComponent: function() {
toBeTextComponentWithValue: function(val) {
var elementType = typeof this._instance._currentElement;
expect(elementType === 'string' || elementType === 'number').toBe(true);
expect(this._instance._stringText).toBe(val);
return this;
},