-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
57 lines (49 loc) · 2.12 KB
/
index.test.ts
File metadata and controls
57 lines (49 loc) · 2.12 KB
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
57
import sbp from '@sbp/sbp'
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import './index.js'
describe('[SBP] DATA domain', () => {
it('should store simple value', () => {
sbp('okTurtles.data/set', 'test', 1)
assert.equal(sbp('okTurtles.data/get', 'test'), 1)
})
it('should reset value', () => {
sbp('okTurtles.data/set', 'reset', 1)
sbp('okTurtles.data/set', 'reset', 2)
assert.equal(sbp('okTurtles.data/get', 'reset'), 2)
})
it('should add item to collection', () => {
sbp('okTurtles.data/add', 'testCollection', 1)
sbp('okTurtles.data/add', 'testCollection', 2)
assert.deepEqual(sbp('okTurtles.data/get', 'testCollection'), [1, 2])
})
it('should return undefined for unset path', () => {
assert.equal(sbp('okTurtles.data/get', 'testNothing'), undefined)
sbp('okTurtles.data/delete', 'testCollection')
assert.equal(sbp('okTurtles.data/get', 'testCollection'), undefined)
})
it('should add and remove fn from collection', (t) => {
const testFn = t.mock.fn()
sbp('okTurtles.data/add', 'fnTestCollection', 1)
sbp('okTurtles.data/add', 'fnTestCollection', testFn)
assert.equal(testFn.mock.callCount(), 0)
sbp('okTurtles.data/get', 'fnTestCollection')[1]()
assert.equal(testFn.mock.callCount(), 1)
sbp('okTurtles.data/remove', 'fnTestCollection', testFn)
assert.deepEqual(sbp('okTurtles.data/get', 'fnTestCollection'), [1])
})
it('should apply String fn to key "test"', () => {
assert.equal(typeof sbp('okTurtles.data/apply', 'test', String), 'string')
assert.equal(sbp('okTurtles.data/apply', 'test', String), '1')
})
it('should return the correct count', () => {
assert.equal(sbp('okTurtles.data/keyCount'), 3)
})
it('should iterate over keys', () => {
const iterator = sbp('okTurtles.data/iterKeys')
assert.deepEqual(iterator.next(), { done: false, value: 'test' })
assert.deepEqual(iterator.next(), { done: false, value: 'reset' })
assert.deepEqual(iterator.next(), { done: false, value: 'fnTestCollection' })
assert.deepEqual(iterator.next(), { done: true, value: undefined })
})
})