-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjson-test.ts
More file actions
34 lines (27 loc) · 1.04 KB
/
json-test.ts
File metadata and controls
34 lines (27 loc) · 1.04 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
import { readJSON, writeJSON } from '../src/json.ts'
const jsonReadPath = './examples/json/data.json'
const jsonWritePath = './examples/json/json-test.json'
const jsonIndentWritePath = './examples/json/json-indent-test.json'
Deno.test("reads a json file", async () => {
const json = await readJSON(jsonReadPath)
assertObjectMatch(json, { media_type: "image", service_version: "v1" });
})
Deno.test("writes a json file", async () => {
const data = {
prices: '$20',
name: 'table'
}
await writeJSON(jsonWritePath, data)
const json = await readJSON(jsonWritePath)
assertObjectMatch(json, { prices: "$20", name: "table" });
})
Deno.test("writes a json file with space indent", async () => {
const data = {
prices: '$20',
name: 'table'
}
await writeJSON(jsonIndentWritePath, data, null, 2)
const json = await readJSON(jsonIndentWritePath)
assertObjectMatch(json, { prices: "$20", name: "table" });
})