-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (32 loc) · 1.18 KB
/
test.js
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
import {test} from 'tape'
import {
fetchCurrentPosition,
positions,
} from './index.js'
const validatePosEvent = (t, pos, name = 'pos') => {
t.deepEqual(Object.keys(pos), [
'latitude',
'longitude',
'speed',
])
t.equal(typeof pos.latitude, 'number', name + '.latitude must be a number')
t.ok(!Number.isNaN(pos.latitude), name + '.latitude must not be NaN')
t.equal(typeof pos.longitude, 'number', name + '.longitude must be a number')
t.ok(!Number.isNaN(pos.longitude), name + '.longitude must not be NaN')
t.equal(typeof pos.speed, 'number', name + '.speed must be a number')
t.ok(!Number.isNaN(pos.speed), name + '.speed must not be NaN')
}
test('fetchCurrentPosition works', async (t) => {
const res = await fetchCurrentPosition()
validatePosEvent(t, res, 'res')
})
test('positions works', async (t) => {
const asyncIt = positions()[Symbol.asyncIterator]()
const {done: done1, value: pos1} = await asyncIt.next()
t.equal(done1, false, 'it 0: .done')
validatePosEvent(t, pos1, 'pos1')
await new Promise(resolve => setTimeout(resolve, 1000))
const {done: done2, value: pos2} = await asyncIt.next()
t.equal(done2, false, 'it 0: .done')
validatePosEvent(t, pos2, 'pos2')
})