mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
32 lines
825 B
TypeScript
32 lines
825 B
TypeScript
import React from 'react'
|
|
import renderer from 'react-test-renderer'
|
|
import Link from '../components/Link'
|
|
|
|
function toJson(component: renderer.ReactTestRenderer) {
|
|
const result = component.toJSON()
|
|
expect(result).toBeDefined()
|
|
expect(result).not.toBeInstanceOf(Array)
|
|
return result as renderer.ReactTestRendererJSON
|
|
}
|
|
|
|
test('Link changes the class when hovered', () => {
|
|
const component = renderer.create(
|
|
<Link page="http://antfu.me">Anthony Fu</Link>,
|
|
)
|
|
let tree = toJson(component)
|
|
expect(tree).toMatchSnapshot()
|
|
|
|
// manually trigger the callback
|
|
tree.props.onMouseEnter()
|
|
|
|
// re-rendering
|
|
tree = toJson(component)
|
|
expect(tree).toMatchSnapshot()
|
|
|
|
// manually trigger the callback
|
|
tree.props.onMouseLeave()
|
|
// re-rendering
|
|
tree = toJson(component)
|
|
expect(tree).toMatchSnapshot()
|
|
})
|