-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
load-toml.js
38 lines (31 loc) · 933 Bytes
/
load-toml.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
"use strict";
const { outdent } = require("outdent");
const loadToml = require("../../../src/utils/load-toml.js");
describe("TOML", () => {
const exampleFilePath = "example.toml";
const exampleToml = outdent`
# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
`;
const wrongToml = "///ERROR///";
test("loads toml successfully", () => {
const parsedToml = loadToml(exampleFilePath, exampleToml);
expect(parsedToml).toMatchSnapshot();
});
test("throws error on incorrect toml", () => {
expect(() => {
loadToml(exampleFilePath, wrongToml);
}).toThrow();
expect(() => {
loadToml(exampleFilePath, wrongToml);
}).toThrowErrorMatchingSnapshot();
});
});