Sha256: 7ff5853e369f7087258980bfdbabd45a4116d7cc4d1102aab4b4d4f3a165f5cb

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

require "spec_helper"

describe Event do
  html <<-HTML
    <div id="on-spec">
      <div id="foo">
        <div id="bar"></div>
      </div>
      <div id="baz"></div>
    </div>
  HTML

  it '#current_target returns the current element in the bubbling' do
    foo = Element['#foo']
    bar = Element['#bar']
    result = []

    foo.on(:click) { |e| result << e.current_target.id }
    bar.on(:click) { |e| result << e.current_target.id }

    foo.trigger(:click)
    result.should == ['foo']
    result = []

    bar.trigger(:click)
    result.should == ['bar', 'foo']
  end

  it '#type returns the type of event' do
    type = nil
    foo  = Element['#foo']

    foo.on(:click) { |e| type = e.type }
    foo.on(:mousedown) { |e| type = e.type }
    foo.on(:opal_random) { |e| type = e.type }

    foo.trigger(:click)
    type.should == :click

    foo.trigger(:mousedown)
    type.should == :mousedown

    foo.trigger(:opal_random)
    type.should == :opal_random
  end

  it '#target returns a JQuery wrapper around the element that triggered the event' do
    foo = Element['#foo']
    bar = Element['#bar']
    target = nil

    foo.on(:click) { |e| target = e.target.id }

    foo.trigger(:click)
    target.should == 'foo'

    bar.trigger(:click)
    target.should == 'bar'
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opal-jquery-0.4.2 spec/event_spec.rb
opal-jquery-0.4.1 spec/event_spec.rb
opal-jquery-0.4.0 spec/event_spec.rb
opal-jquery-0.3.0 spec/event_spec.rb
opal-jquery-0.3.0.beta2 spec/event_spec.rb
opal-jquery-0.3.0.beta1 spec/event_spec.rb
opal-jquery-0.2.0 spec/event_spec.rb
opal-jquery-0.1.2 spec/event_spec.rb
opal-jquery-0.1.1 spec/event_spec.rb
opal-jquery-0.1.0 spec/event_spec.rb
opal-jquery-0.0.13 spec/event_spec.rb
opal-jquery-0.0.12 spec/event_spec.rb
opal-jquery-0.0.11 spec/event_spec.rb
opal-jquery-0.0.9 spec/event_spec.rb
opal-jquery-0.0.8 spec/event_spec.rb
opal-jquery-0.0.7 spec/event_spec.rb