From c9fb5b258ee40320aa14aa010b1737021226b7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 2 Dec 2014 17:52:26 -0800 Subject: [PATCH] Add toBeTextComponentWithValue to reactComponentExpect This was previously possible by looking at renderedChildren and props but this feels better. --- .../__tests__/ReactMultiChildText-test.js | 2 +- .../__tests__/reactComponentExpect-test.js | 49 +++++++++++++++++++ src/test/reactComponentExpect.js | 3 +- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/test/__tests__/reactComponentExpect-test.js diff --git a/src/core/__tests__/ReactMultiChildText-test.js b/src/core/__tests__/ReactMultiChildText-test.js index 6457a902d2..7cdce88b7a 100644 --- a/src/core/__tests__/ReactMultiChildText-test.js +++ b/src/core/__tests__/ReactMultiChildText-test.js @@ -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; diff --git a/src/test/__tests__/reactComponentExpect-test.js b/src/test/__tests__/reactComponentExpect-test.js new file mode 100644 index 0000000000..b29d73cf70 --- /dev/null +++ b/src/test/__tests__/reactComponentExpect-test.js @@ -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 ( +
+
This is a div
+ {'This is text'} +
+ ); + } + }); + + var component = ReactTestUtils.renderIntoDocument(); + + reactComponentExpect(component) + .expectRenderedChild() + .expectRenderedChildAt(1) + .toBeTextComponentWithValue('This is text'); + }); +}); + diff --git a/src/test/reactComponentExpect.js b/src/test/reactComponentExpect.js index 956c81290c..2f2df87f25 100644 --- a/src/test/reactComponentExpect.js +++ b/src/test/reactComponentExpect.js @@ -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; },