mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import '@testing-library/jest-dom'
|
|
import { z } from 'zod'
|
|
import withValidation from '.'
|
|
import { noop } from 'lodash-es'
|
|
|
|
describe('withValidation HOC', () => {
|
|
// schema for validation
|
|
const schema = z.object({ name: z.string() })
|
|
type Props = z.infer<typeof schema> & {
|
|
age: number
|
|
}
|
|
|
|
const TestComponent = ({ name, age }: Props) => (
|
|
<div>{name} - {age}</div>
|
|
)
|
|
const WrappedComponent = withValidation(TestComponent, schema)
|
|
|
|
beforeAll(() => {
|
|
jest.spyOn(console, 'error').mockImplementation(noop)
|
|
})
|
|
|
|
afterAll(() => {
|
|
jest.restoreAllMocks()
|
|
})
|
|
|
|
it('renders the component when validation passes', () => {
|
|
render(<WrappedComponent name='Valid Name' age={30} />)
|
|
expect(screen.getByText('Valid Name - 30')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders the component when props is invalid but not in schema ', () => {
|
|
render(<WrappedComponent name='Valid Name' age={'aaa' as any} />)
|
|
expect(screen.getByText('Valid Name - aaa')).toBeInTheDocument()
|
|
})
|
|
|
|
it('does not render the component when validation fails', () => {
|
|
render(<WrappedComponent name={123 as any} age={30} />)
|
|
expect(screen.queryByText('123 - 30')).toBeNull()
|
|
})
|
|
})
|