react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / __tests__ / sliceChildren-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('sliceChildren', function() {1415var React;16var ReactTestUtils;1718var sliceChildren;19var reactComponentExpect;2021var Partial;2223beforeEach(function() {24React = require('React');25ReactTestUtils = require('ReactTestUtils');2627sliceChildren = require('sliceChildren');28reactComponentExpect = require('reactComponentExpect');2930Partial = React.createClass({31render: function() {32return (33<div>34{sliceChildren(35this.props.children,36this.props.start,37this.props.end38)}39</div>40);41}42});43});4445function renderAndSlice(set, start, end) {46var instance = <Partial start={start} end={end}>{set}</Partial>;47instance = ReactTestUtils.renderIntoDocument(instance);48var rendered = reactComponentExpect(instance)49.expectRenderedChild()50.instance();51return rendered.props.children;52}5354it('should render the whole set if start zero is supplied', function() {55var fullSet = [56<div key="A" />,57<div key="B" />,58<div key="C" />59];60var children = renderAndSlice(fullSet, 0);61expect(children).toEqual({62'.$A': fullSet[0],63'.$B': fullSet[1],64'.$C': fullSet[2]65});66});6768it('should render the remaining set if no end index is supplied', function() {69var fullSet = [70<div key="A" />,71<div key="B" />,72<div key="C" />73];74var children = renderAndSlice(fullSet, 1);75expect(children).toEqual({76'.$B': fullSet[1],77'.$C': fullSet[2]78});79});8081it('should exclude everything at or after the end index', function() {82var fullSet = [83<div key="A" />,84<div key="B" />,85<div key="C" />,86<div key="D" />87];88var children = renderAndSlice(fullSet, 1, 2);89expect(children).toEqual({90'.$B': fullSet[1]91});92});9394it('should allow static children to be sliced', function() {95var a = <div />;96var b = <div />;97var c = <div />;9899var instance = <Partial start={1} end={2}>{a}{b}{c}</Partial>;100instance = ReactTestUtils.renderIntoDocument(instance);101var rendered = reactComponentExpect(instance)102.expectRenderedChild()103.instance();104105expect(rendered.props.children).toEqual({106'.1': b107});108});109110});111112113