yamlDenormalizer.test.ts 730 B

1234567891011121314151617181920212223
  1. import {describe, test, expect} from "vitest";
  2. import YamlEncoder from "~/services/encoder/yamlEncoder";
  3. import {load} from "js-yaml";
  4. describe('encode', () => {
  5. test('simple conversion', () => {
  6. const result = YamlEncoder.encode({title: {a: 1, b: 2, c: ['foo', 'bar']}})
  7. expect(result).toEqual(`title:\n a: 1\n b: 2\n c:\n - foo\n - bar\n`)
  8. })
  9. })
  10. describe('decode', () => {
  11. test('with empty data', () => {
  12. const result = YamlEncoder.decode("")
  13. expect(result).toBeNull()
  14. })
  15. test('with data', () => {
  16. const result = YamlEncoder.decode(`title:\n a: 1\n b: 2\n c: [foo, bar]`)
  17. expect(result).toEqual({title: {a: 1, b: 2, c: ['foo', 'bar']}})
  18. })
  19. })