mirror of
https://github.com/supabase/supabase.git
synced 2026-06-22 15:24:24 +08:00
* remove trailing commas * test cases added * Opt for immutable way in JsonEditor --------- Co-authored-by: Joshen Lim <[email protected]>
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { removeJSONTrailingComma } from '/apps/studio/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)
|
|
})
|
|
})
|