Files
supabase/apps/studio/tests/components/Editor/RemoveJSONTrailingComma.utils.test.ts
Jordi Enric 764d10986d vitest & msw integration (#26303)
* 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

* Replace jest with vitest

* Rename all *.test.js to *.test.ts

* Configure vitest to work with jsx

* fix vitest issues, fix tests, skip broken tests, add msw, add next-router-mock

* uncomment file

* add tests for msw and nrm

* Fix failing tests

* fix tests in RowEditor

* fix datepicker tests

* fix type errors and comment out tests that need some refactoring

* leave 1 test so test script works

* rm clog and aaaaa

* rename script

* move msw to studio

* add pckg json which i forgot in last commit

* rm consolelog

* move vitest ui dep

* Move next-router-mock to studio.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: TzeYiing <ty@tzeyiing.com>
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2024-05-29 17:31:20 +02:00

37 lines
1.4 KiB
TypeScript

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)
})
})