@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
27 lines (22 loc) • 1 kB
text/typescript
import { describe, expect, it } from 'vitest'
import { stringifyUnknownJson } from '@/utilities/stringifyUnknownJson'
describe('json', () => {
it('stringifyUnknownJson', () => {
// valid json
expect(stringifyUnknownJson(true)).toBe('true')
expect(stringifyUnknownJson(1)).toBe('1')
expect(stringifyUnknownJson('1')).toBe('1')
expect(stringifyUnknownJson('foo')).toBe('foo')
expect(stringifyUnknownJson({ foo: 'bar' })).toBe('{"foo":"bar"}')
expect(stringifyUnknownJson('{}')).toBe('{}')
expect(stringifyUnknownJson(null)).toBe('null')
expect(stringifyUnknownJson('null')).toBe('null')
expect(stringifyUnknownJson([1, 2, 3])).toBe('[1,2,3]')
expect(stringifyUnknownJson(['foo', 'bar'])).toBe('["foo","bar"]')
const date = new Date()
expect(stringifyUnknownJson(date)).toBe(`"${date.toISOString()}"`)
// invalid json
expect(stringifyUnknownJson('"foo')).toBe('"foo')
expect(stringifyUnknownJson('{ "foo": ')).toBe('{ "foo": ')
})
})