mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { removeJSONTrailingComma } from '@/lib/helpers'
|
|
|
|
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)
|
|
})
|
|
})
|