mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add toBeTextComponentWithValue to reactComponentExpect
This was previously possible by looking at renderedChildren and props but this feels better.
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user