Sha256: 6412dce8f7938db28ffae318ac091ac756b546bdf020c559682bb6939a873129

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require "spec_helper"

describe LocalStorage do
  before do
    LocalStorage.clear
  end

  describe '.[]' do
    it 'returns nil when accessing an undefined value' do
      LocalStorage['woosh'].should be_nil
    end

    it 'returns an empty string when set value was also ""' do
      LocalStorage['empty'] = ''
      LocalStorage['empty'].should == ''
    end
  end

  describe '.[]=' do
    it 'sets values in the localstorage' do
      LocalStorage['foo'] = 'Hello World'
      LocalStorage['foo'].should == 'Hello World'
    end

    it 'stores all values as strings' do
      LocalStorage['foo'] = 3.142
      LocalStorage['foo'].should be_kind_of(String)
    end
  end

  describe '.clear' do
    it 'removes all values from the store' do
      LocalStorage['foo'] = 'wow'
      LocalStorage['bar'] = 'pow'
      LocalStorage.clear
      LocalStorage['foo'].should be_nil
      LocalStorage['bar'].should be_nil
    end
  end

  describe '.delete' do
    it 'deletes the given key from localstorage' do
      LocalStorage['deletable'] = 'Hey there'
      LocalStorage.delete 'deletable'
      LocalStorage['deletable'].should be_nil
    end

    it 'returns the deleted value' do
      LocalStorage['deletable'] = 'Hey there'
      LocalStorage.delete('deletable').should == 'Hey there'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-jquery-0.0.7 spec/local_storage_spec.rb
opal-jquery-0.0.6 spec/local_storage_spec.rb
opal-jquery-0.0.5 spec/local_storage_spec.rb