react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / __tests__ / onlyChild-test.js
81155 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @emails react-core9*/1011"use strict";1213describe('onlyChild', function() {1415var React;16var onlyChild;17var WrapComponent;1819beforeEach(function() {20React = require('React');21onlyChild = require('onlyChild');22WrapComponent = React.createClass({23render: function() {24return (25<div>26{onlyChild(this.props.children, this.props.mapFn, this)}27</div>28);29}30});31});3233it('should fail when passed two children', function() {34expect(function() {35var instance =36<WrapComponent>37<div />38<span />39</WrapComponent>;40onlyChild(instance.props.children);41}).toThrow();42});4344it('should fail when passed nully values', function() {45expect(function() {46var instance =47<WrapComponent>48{null}49</WrapComponent>;50onlyChild(instance.props.children);51}).toThrow();5253expect(function() {54var instance =55<WrapComponent>56{undefined}57</WrapComponent>;58onlyChild(instance.props.children);59}).toThrow();60});6162it('should fail when key/value objects', function() {63expect(function() {64var instance =65<WrapComponent>66{{oneThing: <span />}}67</WrapComponent>;68onlyChild(instance.props.children);69}).toThrow();70});717273it('should not fail when passed interpolated single child', function() {74expect(function() {75var instance =76<WrapComponent>77{<span />}78</WrapComponent>;79onlyChild(instance.props.children);80}).not.toThrow();81});828384it('should return the only child', function() {85expect(function() {86var instance =87<WrapComponent>88<span />89</WrapComponent>;90onlyChild(instance.props.children);91}).not.toThrow();92});9394});959697