You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR What is the recommended React Testing Library way to test this?
I successfully upgraded Tailwind (to v3) and React (to v18), but there's a problem: contrary to this library, Enzyme is dead and a move to React Testing Library is unavoidable. That's not a bad thing, RTL is better, but this project was setup using a different philosophy.
Testing like this is discouraged using RTL:
it('should render with large styles',()=>{constexpected='w-10 h-10'constwrapper=mount(<Avatarsrc="test"size="large"/>)expect(wrapper.find(Avatar).getDOMNode().getAttribute('class')).toContain(expected)})
A WIP branch is available here if you want to try something, as I had to create my own version of jest-svg-transformer: master...wip-upgrade
There, you'll find that Avatar was already converted to RTL, while Alert is broken and Backdrop is still WIP.
The text was updated successfully, but these errors were encountered:
I rewrote the tests for the component and also added a test for "Ref". For all other components, I would use this testing way. @estevanmaito Is there any further development of the project planned? I would rewrite all the tests for RTL compatibility.
importReact,{createRef}from'react'import{render,screen,within}from'@testing-library/react'importAvatarfrom'../Avatar'constavatar=()=>screen.getByTestId('avatar')constimg=()=>within(avatar()).getByRole('img')describe('Avatar',()=>{it('should render without crashing',()=>{render(<Avatarsrc="#"/>)expect(avatar()).toBeInTheDocument()})describe('Root',()=>{it('should render with base styles',()=>{constexpectedClasses='relative rounded-full inline-block'render(<Avatarsrc="#"/>)expect(avatar()).toHaveClass(expectedClasses)})describe('prop: ref',()=>{it('should be able to access the <Avatar />',()=>{constavatarRef=createRef<HTMLDivElement>()render(<Avatarref={avatarRef}src="#"/>)expect(avatar()).toEqual(avatarRef.current)})})describe('prop: size',()=>{it('should render with large styles',()=>{constexpectedClasses='w-10 h-10'render(<Avatarsrc="#"size="large"/>)expect(avatar()).toHaveClass(expectedClasses)})it('should render with regular styles',()=>{constexpectedClasses='w-8 h-8'render(<Avatarsrc="#"size="regular"/>)expect(avatar()).toHaveClass(expectedClasses)})it('should render with small styles',()=>{constexpectedClasses='w-6 h-6'render(<Avatarsrc="#"size="small"/>)expect(avatar()).toHaveClass(expectedClasses)})})})describe('Image',()=>{it('should contain an image with the correct src',()=>{constexpectedSrc='#'render(<Avatarsrc="#"/>)expect(img()).toHaveAttribute('src',expectedSrc)})it('should contain an image with alt text',()=>{constexpectedAltText='Lorem'render(<Avatarsrc="#"alt="Lorem"/>)expect(img()).toHaveAccessibleName(expectedAltText)})})})
The reports of my death were greatly exaggerated
TL;DR What is the recommended React Testing Library way to test this?
I successfully upgraded Tailwind (to v3) and React (to v18), but there's a problem: contrary to this library, Enzyme is dead and a move to React Testing Library is unavoidable. That's not a bad thing, RTL is better, but this project was setup using a different philosophy.
Testing like this is discouraged using RTL:
A WIP branch is available here if you want to try something, as I had to create my own version of
jest-svg-transformer
: master...wip-upgradeThere, you'll find that
Avatar
was already converted to RTL, whileAlert
is broken andBackdrop
is still WIP.The text was updated successfully, but these errors were encountered: