mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
refactor(web): migrate to Vitest and esm (#29974)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import React from 'react'
|
||||
import type { IconData } from './IconBase'
|
||||
import IconBase from './IconBase'
|
||||
import * as utils from './utils'
|
||||
|
||||
// Mock the utils module
|
||||
jest.mock('./utils', () => ({
|
||||
generate: jest.fn((icon, key, props) => (
|
||||
vi.mock('./utils', () => ({
|
||||
generate: vi.fn((icon, key, props) => (
|
||||
<svg
|
||||
data-testid="mock-svg"
|
||||
key={key}
|
||||
@ -25,7 +24,7 @@ describe('IconBase Component', () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('renders properly with required props', () => {
|
||||
@ -48,7 +47,7 @@ describe('IconBase Component', () => {
|
||||
})
|
||||
|
||||
it('handles onClick events', () => {
|
||||
const handleClick = jest.fn()
|
||||
const handleClick = vi.fn()
|
||||
render(<IconBase data={mockData} onClick={handleClick} />)
|
||||
const svg = screen.getByTestId('mock-svg')
|
||||
fireEvent.click(svg)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import type { AbstractNode } from './utils'
|
||||
import { generate, normalizeAttrs } from './utils'
|
||||
import { render } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
|
||||
describe('generate icon base utils', () => {
|
||||
describe('normalizeAttrs', () => {
|
||||
@ -41,7 +40,7 @@ describe('generate icon base utils', () => {
|
||||
const { container } = render(generate(node, 'key'))
|
||||
// to svg element
|
||||
expect(container.firstChild).toHaveClass('container')
|
||||
expect(container.querySelector('span')).toHaveStyle({ color: 'blue' })
|
||||
expect(container.querySelector('span')).toHaveStyle({ color: 'rgb(0, 0, 255)' })
|
||||
})
|
||||
|
||||
// add not has children
|
||||
|
||||
Reference in New Issue
Block a user