-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.ts
31 lines (28 loc) · 1.08 KB
/
utils_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
import { delay, lazyJSONParse, pathsAreEqual } from './utils.ts'
import { assertEquals, assert } from 'https://deno.land/[email protected]/testing/asserts.ts'
Deno.test('lazyJSONParse', async (t) => {
await t.step('should parse JSON like JSON.parse', () => {
assertEquals(lazyJSONParse('{ "a": "b" }'), JSON.parse('{ "a": "b" }'))
})
await t.step('should return an empty object on failed parse', () => {
assertEquals(lazyJSONParse('{ "a": "b"'), {})
})
})
Deno.test('pathsAreEqual', async (t) => {
await t.step('if expected path is asterisk, return true', () => {
assertEquals(pathsAreEqual('/hello', '*'), true)
})
await t.step('should assert equal paths', () => {
assertEquals(pathsAreEqual('/hello', '/hello'), true)
})
await t.step('if nothing is expected, default to "/"', () => {
assertEquals(pathsAreEqual('/'), true)
})
})
Deno.test('delay', async (t) => {
await t.step('it delays a function for given time', async () => {
const then = performance.now()
await delay(10)
assert(performance.now() - then < 15) // there's extra run-time
})
})