Sha256: 1e1f6cb20e2ff4113462c83439a78d4dcbb7eed5c7a71594b22ca9b9e1fbafc4

Contents?: true

Size: 865 Bytes

Versions: 15

Compression:

Stored size: 865 Bytes

Contents

require 'native'

describe Hash do
  it 'turns a native JS object into a hash' do
    obj = %x{
      {
        a: 1,
        b: "two",
        c: {
          d: 1,
        },
        e: [
          {
            f: 'g',
          },
        ],
      }
    }

    h = Hash.new(obj)
    expected_hash = {
      a: 1,
      b: "two",
      c: {
        d: 1,
      },
      e: [
        {
          f: 'g',
        },
      ],
    }

    expect(h).to eq(expected_hash)
  end

  describe '#to_n' do
    it 'converts a hash with native objects as values' do
      obj = { 'a_key' => `{ key: 1 }` }
      native = obj.to_n
      `#{native}.a_key.key`.should == 1
    end

    it 'passes Ruby objects that cannot be converted' do
      object = Object.new
      hash = { foo: object }
      native = hash.to_n
      expect(`#{native}.foo`).to eq object
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
opal-0.10.6 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.6.beta spec/opal/stdlib/native/hash_spec.rb
opal-0.10.5 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.4 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.3 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.2 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.1 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.rc2 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.rc1 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.beta5 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.beta4 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.beta3 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.beta2 spec/opal/stdlib/native/hash_spec.rb
opal-0.10.0.beta1 spec/opal/stdlib/native/hash_spec.rb