Files
ComfyUI_frontend/src/scripts/ui/utils.test.ts
huang47 df78c566a5 test: replace unsafe type assertions with fromPartial in coverage tests
Replace double assertions (as unknown as T), as never, fromAny, and
partial-literal casts with fromPartial<T>() from @total-typescript/shoehorn
throughout the coverage-expansion test suite. Fix cross-test prototype
pollution in app.core.test.ts by keeping the updateVueAppNodeDefs spy on
the app instance rather than its prototype. Fix subgraphNavigationStore
tests to use fromPartial<Subgraph> instead of as never for mock assignment.
2026-07-03 14:45:57 -07:00

46 lines
1.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { applyClasses, toggleElement } from './utils'
describe('ui utils', () => {
it('applies string, array, object, and required classes', () => {
const element = document.createElement('div')
applyClasses(element, 'one two', 'required')
expect([...element.classList]).toEqual(['one', 'two', 'required'])
applyClasses(element, ['three', 'four'])
expect([...element.classList]).toEqual(['three', 'four'])
applyClasses(element, { five: true, six: false, seven: true })
expect([...element.classList]).toEqual(['five', 'seven'])
applyClasses(element, null)
expect(element.className).toBe('')
})
it('toggles an element through a placeholder', () => {
const parent = document.createElement('div')
const element = document.createElement('span')
const onHide = vi.fn()
const onShow = vi.fn()
parent.append(element)
const toggle = toggleElement(element, { onHide, onShow })
toggle(false)
expect(parent.firstChild).toBeInstanceOf(Comment)
expect(onHide).toHaveBeenCalledWith(element)
toggle(true)
expect(parent.firstChild).toBe(element)
expect(onShow).toHaveBeenCalledWith(element, true)
toggle('visible')
expect(onShow).toHaveBeenCalledWith(element, 'visible')
toggle(false)
expect(parent.firstChild).toBeInstanceOf(Comment)
expect(onHide).toHaveBeenCalledTimes(2)
})
})