-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
56 lines (41 loc) · 1.25 KB
/
index.test.ts
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
46
47
48
49
50
51
52
53
54
55
56
import {getItem, setItem} from '@rambler-tech/local-storage'
import {initDebug} from '.'
class LocalStorage implements LocalStorage {
map: {[key: string]: any} = {}
getItem(key: string): void {
return this.map[key]
}
setItem(key: string, value: any): void {
this.map[key] = value
}
removeItem(key: string): void {
delete this.map[key]
}
}
Object.defineProperty(window, 'localStorage', {
value: new LocalStorage()
})
test('reset local storage debug value', () => {
setItem('debug', 'test', {raw: true})
expect(getItem('debug', {raw: true})).toBe('test')
initDebug('https://foobar.ru?debug=unset')
expect(getItem('debug', {raw: true})).toBeNull()
})
test('use window.location.href value', () => {
Object.defineProperty(window, 'location', {
value: {
href: 'https://test.ru?debug=bar'
},
writable: true
})
setItem('debug', 'foo', {raw: true})
expect(getItem('debug', {raw: true})).toBe('foo')
initDebug()
expect(getItem('debug', {raw: true})).toBe('bar')
})
test('use debug value from initDebug arg', () => {
setItem('debug', 'test', {raw: true})
expect(getItem('debug', {raw: true})).toBe('test')
initDebug('https://foobar.ru?debug=foo')
expect(getItem('debug', {raw: true})).toBe('foo')
})