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
In order to properly test shadcn's Select component we need to mock PointerEvent this was mentioned in radix-ui/primitives#1822
import{render,screen,within}from'@testing-library/vue';importuserEventfrom'@testing-library/user-event';import{Select,SelectContent,SelectGroup,SelectItem,SelectTrigger,SelectValue,}from'@/components/ui/select'classMockPointerEventextendsEvent{button: number;ctrlKey: boolean;pointerType: string;constructor(type: string,props: PointerEventInit){super(type,props);this.button=props.button||0;this.ctrlKey=props.ctrlKey||false;this.pointerType=props.pointerType||'mouse';}}window.PointerEvent=MockPointerEventasany;window.HTMLElement.prototype.scrollIntoView=vi.fn();window.HTMLElement.prototype.releasePointerCapture=vi.fn();window.HTMLElement.prototype.hasPointerCapture=vi.fn();it('should pass',async()=>{constuser=userEvent.setup();render(<Select><SelectTriggeraria-label="Food"><SelectValueplaceholder="Select a fruit..."/></SelectTrigger><SelectContent><SelectGroup><SelectItemvalue="apple">Apple</SelectItem><SelectItemvalue="banana">Banana</SelectItem></SelectGroup></SelectContent></Select>);//look for the select triggerconsttrigger=screen.getByRole('combobox',{name: 'Food',});//click on the triggerawaituser.click(trigger)//look for the apple option constoption=screen.getByRole('option',{name: 'Apple'})//click on the apple optionawaituser.click(option)});
Expected behavior
Should not display the Vue Warning
Context & Screenshots (if applicable)
For added context, this also happens with @testing-library/react but with a different set of warnings. Here's the codesandbox link
The text was updated successfully, but these errors were encountered:
Environment
Link to minimal reproduction
N/A
Steps to reproduce
vitest
on the test fileDescribe the bug
While running
vitest
to perform component testing for a custom component I have containingshadcn
'sSelect
component, it displays aVue Warning
Here's the stack trace
In order to properly test
shadcn
'sSelect
component we need to mockPointerEvent
this was mentioned in radix-ui/primitives#1822Expected behavior
Vue Warning
Context & Screenshots (if applicable)
@testing-library/react
but with a different set of warnings. Here's the codesandbox linkThe text was updated successfully, but these errors were encountered: