Sha256: 2ed8f52838913105c775d4a89be6995b9bb6bf4e71b7748ab07cc5e54a6846ab

Contents?: true

Size: 1.88 KB

Versions: 16

Compression:

Stored size: 1.88 KB

Contents

require "spec_helper"

describe "Element#class_name" do
  html <<-HTML
    <div id="foo" class="whiskey"></div>
    <div id="bar" class="scotch brandy"></div>
    <div id="baz" class=""></div>
    <div id="buz"></div>

    <div class="red dark"></div>
    <div class="red light"></div>
  HTML

  it "should return the elements' class name" do
    Element.find('#foo').class_name.should == "whiskey"
    Element.find('#bar').class_name.should == "scotch brandy"
  end

  it "should return an empty string for element with no class name" do
    Element.find('#baz').class_name.should == ""
    Element.find('#buz').class_name.should == ""
  end

  it "should return class name for first element if more than 1 in set" do
    Element.find('.red').class_name.should == "red dark"
  end

  it "should return an empty string for instances with no elements" do
    Element.find('.no-elements').class_name.should == ""
  end
end

describe "Element#class_name=" do
  before do
    @div = Element.parse <<-HTML
      <div id="class-name-set-spec">
        <div id="foo" class=""></div>
        <div id="bar" class="oranges"></div>

        <div id="baz" class="banana"></div>
        <div id="buz" class="banana"></div>
      </div>
    HTML

    @div.append_to_body
  end

  after do
    @div.remove
  end

  it "should set the given class name on the element" do
    Element.find('#foo').class_name = "apples"
    Element.find('#foo').class_name.should == "apples"
  end

  it "should replace any existing class name" do
    bar = Element.find('#bar')
    bar.class_name.should == "oranges"

    bar.class_name = "lemons"
    bar.class_name.should == "lemons"
  end

  it "should set the class name on all elements in instance" do
    el = Element.find '.banana'
    el.length.should == 2

    el.class_name = "pop"

    Element.find('#baz').class_name.should == "pop"
    Element.find('#buz').class_name.should == "pop"
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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