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
I created a component test where I would test the value of prop in a Slider component:
import{render,screen}from"@testing-library/react"importmockRouterfrom"next-router-mock"import{AppRouterContext}from"next/dist/shared/lib/app-router-context.shared-runtime"import{Provider}from"react-redux"import{describe,expect,it,vi}from"vitest"import{store}from"@/redux/store"import{PanelMeasuresSliders,sliders}from"../components/panel-measures/sliders"import{PanelMeasures,updatePanelMeasures}from"../state/slice"constdefaultDimensions: PanelMeasures={border: 0.02,distance: 0.02,width: 1.13,length: 1.76,neighborSpace: 0,obstructionSpace: 0.02,}vi.mock("next/navigation",()=>({useParams: vi.fn(()=>({id: "17457534"})),}))describe("Panel Measures Sliders Component",()=>{store.dispatch(updatePanelMeasures(defaultDimensions))it("should render sliders with correct default values",async()=>{render(<AppRouterContext.Providervalue={mockRouterasany}><Providerstore={store}><PanelMeasuresSliders/></Provider></AppRouterContext.Provider>)sliders.forEach(({ valueKey },index)=>{constslider=screen.getByTestId(`dimension-slider-${index}`)constlabel=screen.getByTestId(`dimension-label-${index}`)constexpectedValue=defaultDimensions[valueKeyaskeyofPanelMeasures]?.toString().replace(".",",")constactualLabelContent=label.textContent// Check the slider's value propexpect(slider).toHaveAttribute("value",`[${expectedValue}]`)// Check the label contentexpect(actualLabelContent).toBe(expectedValue)// This passed})})})
While the test ensures that the values are defined in the label but the when it comes to the value property in the the Slider it says that value is null!
Slider
{sliders.map(({ label, valueKey, min, max, step },index)=>(<Cardkey={valueKey}className='rounded-xl'><CardContentclassName='flex flex-col p-0 px-4 pt-4 pb-6'><spanclassName='flex justify-between items-baseline'><spanclassName='flex items-center'><LabelclassName='mr-1'>{label}</Label></span><pclassName='text-lg font-semibold align-sub'><spandata-testid={`dimension-label-${index}`}>{measures[valueKeyaskeyofPanelMeasures]?.toString().replace(".",",")}</span><spanclassName='text-sm text-slate-500 ml-1'>m</span></p></span><Slidermin={min}max={max}step={step}value={[measures[valueKeyaskeyofPanelMeasures]]}onValueChange={(val: number[])=>handleNumberInputChange(valueKey,val)}className='cursor-pointer mt-3'data-testid={`dimension-slider-${index}`}/>{valueKey==="distance"&&(<CardDescriptionclassName='mt-3 text-[13px]'>
Dieser Parameter hat nur Auswirkungen auf Steildächer.
</CardDescription>)}</CardContent></Card>))}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I created a component test where I would test the value of prop in a Slider component:
While the test ensures that the values are defined in the label but the when it comes to the
value
property in the the Slider it says that value is null!Slider
Beta Was this translation helpful? Give feedback.
All reactions