persona-community-5/.pnpm-store/v3/files/fd/33656630b81f3b17fa543451f9b187946bd9f628f23aa1ab19fb1e657ea17de286f938df39c76cf676b25923ec45af270ca6671e2577396c77bf9dcb5787a6
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

74 lines
1.6 KiB
Plaintext

import { outdent } from 'outdent';
import { parseYaml, stringifyYaml } from '../js-yaml';
const yaml = `
emptyValue:
spaces in keys: spaces in keys
numberString: '0123456789'
number: 1000
decimal: 12.34
boolean: true
dateWithoutQuotes: 2020-01-01
dateWithQuotes: '2020-01-01'
array:
- 1
- 2
object:
key1: 1
key2: 2
`;
const yamlToDump = outdent`
date: '2022-01-21T11:29:56.694Z'
dateWithoutQuotes: 2020-01-01
dateWithQuotes: '2020-01-01'
dateImplicit: !!str 2020-01-01
string: test
stringWithQuotes: 'test'
stringWithDoubleQuotes: "test"
`;
const jsObject = {
emptyValue: null,
'spaces in keys': 'spaces in keys',
numberString: '0123456789',
number: 1000,
decimal: 12.34,
boolean: true,
dateWithoutQuotes: '2020-01-01',
dateWithQuotes: '2020-01-01',
array: [1, 2],
object: { key1: 1, key2: 2 },
};
describe('js-yaml', () => {
test('parseYaml', () => {
expect(parseYaml(yaml)).toEqual(jsObject);
});
test('should correctly dump date and string', () => {
expect(stringifyYaml(parseYaml(yamlToDump))).toMatchInlineSnapshot(
`
"date: '2022-01-21T11:29:56.694Z'
dateWithoutQuotes: '2020-01-01'
dateWithQuotes: '2020-01-01'
dateImplicit: '2020-01-01'
string: test
stringWithQuotes: test
stringWithDoubleQuotes: test
"
`
);
});
test('parse and stringify', () => {
expect(parseYaml(stringifyYaml(jsObject))).toEqual(jsObject);
});
test('should throw an error for unsupported types', () => {
expect(() => stringifyYaml({ foo: () => {} })).toThrow(
'unacceptable kind of an object to dump [object Function]'
);
});
});