Skip to content

Commit

Permalink
test(29163): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Jan 10, 2025
1 parent 2e950a7 commit c22e874
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect } from 'vitest'
import { hasNestedError } from '@/components/rjsf/utils/errors.utils.ts'
import { ErrorSchema } from '@rjsf/utils'

interface TestProperty {
test?: object
nested?: {
test1?: object
test2?: object
test3?: object
}
}

const errorGenerator = (msg: undefined | string[], g = false): ErrorSchema<TestProperty> => {
return {
__errors: g ? undefined : msg,
nested: {
__errors: g ? undefined : msg,
test3: { __errors: g ? undefined : msg },
test1: { __errors: msg },
},
}
}

interface TestEachSuite {
schema: ErrorSchema<TestProperty> | undefined
hasError: boolean
}

const allTests: TestEachSuite[] = [
{ schema: undefined, hasError: false },
{ schema: { __errors: undefined }, hasError: false },
{ schema: { __errors: [] }, hasError: false },
{ schema: { __errors: ['This is an error'] }, hasError: true },
{ schema: errorGenerator(undefined), hasError: false },
{ schema: errorGenerator([]), hasError: false },
{ schema: errorGenerator(['This is an error']), hasError: true },
{ schema: errorGenerator(['This is an error'], true), hasError: true },
]

describe('hasNestedError', () => {
it.each<TestEachSuite>(allTests)('should returns $expected with $schema', ({ schema, hasError }) => {
expect(hasNestedError<TestProperty>(schema)).toStrictEqual(hasError)
})
})

0 comments on commit c22e874

Please sign in to comment.