summaryrefslogtreecommitdiff
path: root/packages/webapi/test/storage.js
blob: b8a6d23547b67afc73ced782542fa82c5fbe27b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { assert, test } from '../run/test.setup.js'
import { polyfill } from '../mod.js'

test(() => {
	return [
		{
			name: 'Includes Storage functionality',
			test() {
				const target = {}

				polyfill(target)
	
				assert.equal(Reflect.has(target, 'Storage'), true)
				assert.equal(Reflect.has(target, 'localStorage'), true)
				assert.equal(typeof target.Storage, 'function')
				assert.equal(typeof target.localStorage, 'object')
			},
		},
		{
			name: 'Supports Storage methods',
			test() {
				const target = {}

				polyfill(target)

				assert.equal(target.localStorage.setItem('hello', 'world'), undefined)
				assert.equal(target.localStorage.getItem('hello'), 'world')
				assert.equal(target.localStorage.key(0), 'hello')
				assert.equal(target.localStorage.key(1), null)
				assert.equal(target.localStorage.length, 1)
				assert.equal(target.localStorage.setItem('world', 'hello'), undefined)
				assert.equal(target.localStorage.key(1), 'world')
				assert.equal(target.localStorage.key(2), null)
				assert.equal(target.localStorage.length, 2)
				assert.equal(target.localStorage.removeItem('hello'), undefined)
				assert.equal(target.localStorage.key(0), 'world')
				assert.equal(target.localStorage.key(1), null)
				assert.equal(target.localStorage.length, 1)
				assert.equal(target.localStorage.clear(), undefined)
				assert.equal(target.localStorage.key(0), null)
				assert.equal(target.localStorage.length, 0)
			},
		},
	]
})