Sha256: 71d8723dc885b376558805c993268309ea38bbf1086815d08f56e3f68e2d9c25

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# backtick_javascript: true

require 'spec_helper'

describe 'Iterable props defined by Opal on core JS objects' do
  %x{
    function iterableKeysOf(obj) {
      var result = [];

      for (var key in obj) {
        result.push(key);
      }

      return result;
    }
  }

  it 'is empty for numbers' do
    `iterableKeysOf(1)`.should == []
  end

  it 'is empty for strings' do
    `iterableKeysOf('123')`.should == ['0', '1', '2'] # indexes, in JS they are iterable by default
    `iterableKeysOf(new String('123'))`.should == ['0', '1', '2'] # indexes, in JS they are iterable by default
  end

  it 'is empty for plain objects' do
    `iterableKeysOf({})`.should == []
  end

  it 'is empty for boolean' do
    `iterableKeysOf(true)`.should == []
    `iterableKeysOf(false)`.should == []
  end

  it 'is empty for regexp' do
    `iterableKeysOf(/regexp/)`.should == []
  end

  it 'is empty for functions' do
    `iterableKeysOf(function() {})`.should == []
  end

  it 'is empty for dates' do
    `iterableKeysOf(new Date())`.should == []
  end

  it 'is empty for errors' do
    `iterableKeysOf(new Error('message'))`.should == []
  end

  it 'is empty for Math' do
    `iterableKeysOf(Math)`.should == []
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/core/iterable_props_spec.rb
opal-1.8.2 spec/opal/core/iterable_props_spec.rb
opal-1.8.1 spec/opal/core/iterable_props_spec.rb
opal-1.8.0 spec/opal/core/iterable_props_spec.rb
opal-1.8.0.beta1 spec/opal/core/iterable_props_spec.rb
opal-1.8.0.alpha1 spec/opal/core/iterable_props_spec.rb