【发布时间】:2021-11-08 13:25:26
【问题描述】:
如何从测试库反应的 HTML 元素中获取 ref 属性?到目前为止我有这个:
it('element container ref should be null if prop noSwipe is passed', () => {
const onCloseMock = jest.fn()
render(<Wrapper onClose={onCloseMock} noSwipe />)
const container = screen.getByTestId('container')
expect(container.ref).toBeNull() // Want to implement this line
})
【问题讨论】:
-
这个解决方案是我想要的,但是因为我没有使用 Enzyme,所以它不会工作:l 试图获得这个人的 ref
const container = screen.getByTestId('container')它是一个 HTMLElement -
为什么需要从该组件中获取
ref?你能不测试使用ref的行为吗?
标签: javascript reactjs jestjs testing-library