<commit_before>require 'spec_helper'

if opal?
describe React::Children do
  let(:component) {
    Class.new do
      include React::Component
      def render
        div { 'lorem' }
      end
    end
  }
  let(:childs) { [React.create_element('a'), React.create_element('li')] }
  let(:element) { React.create_element(component) { childs } }
  let(:children) { described_class.new(`#{element.to_n}.props.children`) }

  before(:each) do
    React::Test::Utils.render_into_document(element)
  end

  it 'is enumerable' do
    nodes = children.map { |elem| elem.element_type }
    expect(nodes).to eq(['a', 'li'])
  end

  it 'returns an Enumerator when not providing a block' do
    nodes = children.each
    expect(nodes).to be_a(Enumerator)
    expect(nodes.size).to eq(2)
  end

  describe '#each' do
    it 'returns an array of elements' do
      nodes = children.each { |elem| elem.element_type }
      expect(nodes).to be_a(Array)
      expect(nodes.map(&:class)).to eq(childs.map(&:class))
    end
  end

  describe '#length' do
    it 'returns the number of child elements' do
      expect(children.length).to eq(2)
    end
  end

  describe 'with single child element' do
    let(:childs) { [React.create_element('a')] }

    it 'is enumerable containing single element' do
      nodes = children.map { |elem| elem.element_type }
      expect(nodes).to eq(['a'])
    end

    describe '#length' do
      it 'returns the number of child elements' do
        expect(children.length).to eq(1)
      end
    end
  end

  describe 'with no child element' do
    let(:element) { React.create_element(component) }

    it 'is enumerable containing no elements' do
      nodes = children.map { |elem| elem.element_type }
      expect(nodes).to eq([])
    end

    describe '#length' do
      it 'returns the number of child elements' do
        expect(children.length).to eq(0)
      end
    end
  end
end
end
<commit_msg>convert to hyper-spec<commit_after>require 'spec_helper'

describe 'React::Children', js: true do
  describe 'with multiple child elements' do
    before :each do
      on_client do
        class InitTest
          def self.get_children
            component = Class.new do
              include React::Component
              def render
                div { 'lorem' }
              end
            end
            childs = [ React.create_element('a'), React.create_element('li') ]
            element = React.create_element(component) { childs }
            el_children = element.to_n.JS[:props].JS[:children]
            children = React::Children.new(el_children)
            dom_el = JS.call(:eval, "document.body.appendChild(document.createElement('div'))")
            React.render(element, dom_el)
            children
          end
        end
      end
    end

    it 'is enumerable' do
      expect_evaluate_ruby do
        InitTest.get_children.map { |elem| elem.element_type }
      end.to eq(['a', 'li'])
    end

    it 'returns an Enumerator when not providing a block' do
      expect_evaluate_ruby do
        nodes = InitTest.get_children.each
        [nodes.class.name, nodes.size]
      end.to eq(["Enumerator", 2])
    end

    describe '#each' do
      it 'returns an array of elements' do
        expect_evaluate_ruby do
          nodes = InitTest.get_children.each { |elem| elem.element_type }
          [nodes.class.name, nodes.map(&:class)]
        end.to eq(["Array", ["React::Element", "React::Element"]])
      end
    end

    describe '#length' do
      it 'returns the number of child elements' do
        expect_evaluate_ruby do
          InitTest.get_children.length
        end.to eq(2)
      end
    end
  end

  describe 'with single child element' do
    before :each do
      on_client do
        class InitTest
          def self.get_children
            component = Class.new do
              include React::Component
              def render
                div { 'lorem' }
              end
            end
            childs = [ React.create_element('a') ]
            element = React.create_element(component) { childs }
            el_children = element.to_n.JS[:props].JS[:children]
            children = React::Children.new(el_children)
            dom_el = JS.call(:eval, "document.body.appendChild(document.createElement('div'))")
            React.render(element, dom_el)
            children
          end
        end
      end
    end

    it 'is enumerable containing single element' do
      expect_evaluate_ruby do
        InitTest.get_children.map { |elem| elem.element_type }
      end.to eq(["a"])
    end

    describe '#length' do
      it 'returns the number of child elements' do
        expect_evaluate_ruby do
          InitTest.get_children.length
        end.to eq(1)
      end
    end
  end

  describe 'with no child element' do
    before :each do
      on_client do
        class InitTest
          def self.get_children
            component = Class.new do
              include React::Component
              def render
                div { 'lorem' }
              end
            end
            element = React.create_element(component)
            el_children = element.to_n.JS[:props].JS[:children]
            children = React::Children.new(el_children)
            dom_el = JS.call(:eval, "document.body.appendChild(document.createElement('div'))")
            React.render(element, dom_el)
            children
          end
        end
      end
    end

    it 'is enumerable containing no elements' do
      expect_evaluate_ruby do
        InitTest.get_children.map { |elem| elem.element_type }
      end.to eq([])
    end

    describe '#length' do
      it 'returns the number of child elements' do
        expect_evaluate_ruby do
          InitTest.get_children.length
        end.to eq(0)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09775338706911336, 'fraction_numerical': 0.0013719773623735209, 'mean_word_length': 2.0971853425385025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560122', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1671, 'n_words': 459}