Sha256: e5a9e8129ed10728f762b82fb2d42e580251004bf53d691eb2293dd3a202e383

Contents?: true

Size: 847 Bytes

Versions: 5

Compression:

Stored size: 847 Bytes

Contents

# backtick_javascript: true

describe "The rescue keyword" do
  context 'JS::Error' do
    it 'handles raw js throws' do
      begin
        `throw { message: 'foo' }`
        nil
      rescue JS::Error => e
        e.JS[:message]
      end.should == 'foo'
    end

    it 'handles other Opal error' do
      begin
        raise 'bar'
      rescue JS::Error => e
        e.message
      end.should == 'bar'
    end

    it 'can be combined with other classes to catch js errors' do
      begin
        `throw { message: 'baz' }`
        nil
      rescue JS::Error, RuntimeError => e
        e.JS[:message]
      end.should == 'baz'
    end

    it 'can be combined with other classes to catch Opal errors' do
      begin
        raise 'quux'
      rescue JS::Error, RuntimeError => e
        e.message
      end.should == 'quux'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-1.8.2 spec/opal/core/runtime/rescue_spec.rb
opal-1.8.1 spec/opal/core/runtime/rescue_spec.rb
opal-1.8.0 spec/opal/core/runtime/rescue_spec.rb
opal-1.8.0.beta1 spec/opal/core/runtime/rescue_spec.rb
opal-1.8.0.alpha1 spec/opal/core/runtime/rescue_spec.rb