forked from asyncapi/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.test.js
25 lines (21 loc) · 908 Bytes
/
utils.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
const { convertToJson } = require('../scripts/utils.ts');
const { jsonString, yamlString, jsonObject, invalidString } = require('./fixtures/utilsData');
describe('convertToJson', () => {
test('should return JSON object if input is valid JSON string', () => {
expect(convertToJson(jsonString)).toEqual(jsonObject);
});
test('should return JavaScript object if input is valid YAML string', () => {
expect(convertToJson(yamlString)).toEqual(jsonObject);
});
test('should return input if input is already an object', () => {
expect(convertToJson(jsonObject)).toBe(jsonObject);
});
test('should throw an error if input is invalid JSON and invalid YAML', () => {
try {
convertToJson(invalidString);
expect(convertToJson(invalidString)).toBeUndefined();
} catch (error) {
expect(error.message.includes('Invalid content format')).toBeTruthy();
}
});
});