Files
supabase/apps/studio/tests/components/Editor/RemoveJSONTrailingComma.utils.test.js
Joshen Lim d025e0f739 chore/fix studio jest tests (#25872)
* Fix tests in tests/unit, tests/components and files under tests, looking into tests/pages

* Fix tests under pages/projects root

* Fix

* Comment out broken tests that im stuck with

* Fix api-report.test

* Fix storage-report-test

* chore: fix some tests

* chore: remove logging

* Fix LogsPreviewer.test.js

* Fix most of logs-query-test

* Skip broken tests instead of false positiving them

---------

Co-authored-by: TzeYiing <[email protected]>
2024-05-11 12:05:25 +02:00

37 lines
1.4 KiB
JavaScript

import { removeJSONTrailingComma } from 'lib/helpers.ts'
describe('removeJSONTrailingComma', () => {
it('should handle an empty object', () => {
const jsonString = '{}'
expect(removeJSONTrailingComma(jsonString)).toEqual(jsonString)
})
it('should handle an empty array', () => {
const jsonString = '[]'
expect(removeJSONTrailingComma(jsonString)).toEqual(jsonString)
})
it('should handle a JSON string without a trailing comma', () => {
const jsonString = '{"name": "John", "age": 25}'
expect(removeJSONTrailingComma(jsonString)).toEqual(jsonString)
})
it('should remove a trailing comma for JSON object', () => {
const jsonString = '{"name": "John", "age": 25,}'
const expectedOutput = '{"name": "John", "age": 25}'
expect(removeJSONTrailingComma(jsonString)).toEqual(expectedOutput)
})
it('should remove a trailing commas in an array of objects', () => {
const jsonString = '[{"fruit1": "apple","fruit2": "banana",}]'
const expectedOutput = '[{"fruit1": "apple","fruit2": "banana"}]'
expect(removeJSONTrailingComma(jsonString)).toEqual(expectedOutput)
})
it('should remove all trailing commas in an array of objects', () => {
const jsonString = '[{"fruit1": "apple","fruit2": "banana",},]'
const expectedOutput = '[{"fruit1": "apple","fruit2": "banana"}]'
expect(removeJSONTrailingComma(jsonString)).toEqual(expectedOutput)
})
})