最佳答案
我对 JavaScript 测试完全不熟悉,正在一个新的代码库中工作。我想编写一个测试,检查元素上的 className。我与杰斯特和 Ref = “ https://testinglibrary. com/docs/response-testinglibrary/intro/”rel = “ noReferrer”> React TestingLibrary 一起工作。下面我有一个测试,将呈现一个按钮的基础上的 variant
道具。它还包含一个 className,我想测试一下。
it('Renders with a className equal to the variant', () => {
const { container } = render(<Button variant="default" />)
expect(container.firstChild) // Check for className here
})
我试图谷歌一个属性像酶与 hasClass
,但我无法找到任何东西。如何使用当前库(反应测试库和 Jest)解决这个问题?