Skip to main content
edited body
Source Link
Penny Liu
  • 17.9k
  • 5
  • 89
  • 109

You can use toHaveClass from jest DOM

 it('renders textinput with optional classes', () => {   const { container } = render(<TextArea {...props} className='class1' />)   expect(container.children[1]).toHaveClass('class1')  }) 

Don't forgot to destructure response like this {container}{container} Because By default, React Testing Library will create a div and append that div to the document.bodydocument.body and this is where your React component will be rendered. If you provide your own HTMLElementHTMLElement container via this option, it will not be appended to the document.bodydocument.body automatically.

You can use toHaveClass from jest DOM

 it('renders textinput with optional classes', () => {   const { container } = render(<TextArea {...props} className='class1' />)   expect(container.children[1]).toHaveClass('class1')  }) 

Don't forgot to destructure response like this {container} Because By default, React Testing Library will create a div and append that div to the document.body and this is where your React component will be rendered. If you provide your own HTMLElement container via this option, it will not be appended to the document.body automatically.

You can use toHaveClass from jest DOM

it('renders textinput with optional classes', () => { const { container } = render(<TextArea {...props} className='class1' />) expect(container.children[1]).toHaveClass('class1') }) 

Don't forgot to destructure response like this {container} Because By default, React Testing Library will create a div and append that div to the document.body and this is where your React component will be rendered. If you provide your own HTMLElement container via this option, it will not be appended to the document.body automatically.

Source Link

You can use toHaveClass from jest DOM

 it('renders textinput with optional classes', () => { const { container } = render(<TextArea {...props} className='class1' />) expect(container.children[1]).toHaveClass('class1') }) 

Don't forgot to destructure response like this {container} Because By default, React Testing Library will create a div and append that div to the document.body and this is where your React component will be rendered. If you provide your own HTMLElement container via this option, it will not be appended to the document.body automatically.