-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathjson2xml.test.ts
46 lines (39 loc) · 1.12 KB
/
json2xml.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { describe, expect, it } from 'bun:test';
import { json2xml } from './json2xml';
describe('getUrlFromServerState', () => {
it('transforms JSON to xml', () => {
const xml = json2xml({
foo: 'bar',
});
expect(xml).toBe('<?xml version="1.0"?>\n<foo>bar</foo>\n');
});
it('wraps array items', () => {
const xml = json2xml({
urls: {
url: ['https://example.com', 'https://example.com'],
},
});
expect(xml).toBe(
'<?xml version="1.0"?>\n<urls>\n\t<url>https://example.com</url>\n\t<url>https://example.com</url>\n</urls>\n'
);
});
it('indents correctly', () => {
const xml = json2xml({
id: 10,
name: 'doggie',
category: {
id: 1,
name: 'Dogs',
},
photoUrls: ['string'],
tags: [
{
id: 0,
name: 'string',
},
],
status: 'available',
});
expect(xml).toMatchSnapshot();
});
});