spec/element_spec.rb in opal-jquery-0.0.1 vs spec/element_spec.rb in opal-jquery-0.0.2

- old
+ new

@@ -1,23 +1,15 @@ +require "spec_helper" + describe Element do - before do - @div = Document.parse <<-HTML - <div id="on-spec"> - <div id="foo"> - <div id="bar" class="apples"></div> - </div> - <div id="baz"></div> - </div> - HTML + html <<-HTML + <div id="foo"> + <div id="bar" class="apples"></div> + </div> + <div id="baz"></div> + HTML - @div.append_to_body - end - - after do - @div.remove - end - describe '#on' do it 'adds an event listener onto the elements' do count = 0 foo = Document['#foo'] @@ -65,15 +57,27 @@ Document['#foo'].on(:click, &handler).should == handler end it 'has an Event instance passed to the handler' do foo = Document['#foo'] - foo.on :click do |evt| - evt.should be_kind_of(Event) + foo.on :click do |event| + event.should be_kind_of(Event) end foo.trigger(:click) end + + it 'has an Event instance, plus up to three additional parameters passed to the handler' do + foo = Document['#foo'] + foo.on :bozo do |event, foo, bar, baz, buz| + event.should be_kind_of(Event) + foo.should == 'foo' + bar.should == 'bar' + baz.should == 'baz' + buz.should be_nil + end + foo.trigger(:bozo, ['foo', 'bar', 'baz', 'buz']) + end end describe '#off' do it 'removes event handlers that were added using #on' do count = 0 @@ -102,6 +106,6 @@ count.should == 1 bar.trigger(:click) count.should == 1 end end -end \ No newline at end of file +end