0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/webapi/test/storage.js
2022-04-10 18:29:46 -07:00

32 lines
1.3 KiB
JavaScript

import { expect } from 'chai'
import { polyfill } from '../mod.js'
describe('Storage', () => {
const target = {}
before(() => polyfill(target))
it('Includes Storage functionality', () => {
expect(target).to.have.property('Storage').that.is.a('function')
expect(target).to.have.property('localStorage').that.is.an('object')
})
it('Supports Storage methods', () => {
expect(target.localStorage.setItem('hello', 'world')).to.equal(undefined)
expect(target.localStorage.getItem('hello')).to.equal('world')
expect(target.localStorage.key(0)).to.equal('hello')
expect(target.localStorage.key(1)).to.equal(null)
expect(target.localStorage.length).to.equal(1)
expect(target.localStorage.setItem('world', 'hello')).to.equal(undefined)
expect(target.localStorage.key(1)).to.equal('world')
expect(target.localStorage.key(2)).to.equal(null)
expect(target.localStorage.length).to.equal(2)
expect(target.localStorage.removeItem('hello')).to.equal(undefined)
expect(target.localStorage.key(0)).to.equal('world')
expect(target.localStorage.key(1)).to.equal(null)
expect(target.localStorage.length).to.equal(1)
expect(target.localStorage.clear()).to.equal(undefined)
expect(target.localStorage.key(0)).to.equal(null)
expect(target.localStorage.length).to.equal(0)
})
})