MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Example

Function Example

packages/react-aria-components/test/Select.test.js:881–913  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

879
880 it('has a value immediately after rendering', async () => {
881 function Example() {
882 const ref = useRef(null);
883 const [formData, setFormData] = useState(() => new FormData());
884
885 useEffect(() => {
886 if (ref.current) {
887 setFormData(new FormData(ref.current));
888 }
889 }, []);
890
891 const selectValue = formData.get('select');
892
893 if (selectValue instanceof File) {
894 throw new Error('');
895 }
896
897 return (
898 <form ref={ref}>
899 <Select name="select" defaultValue="1" aria-label="Select">
900 <Button>
901 <SelectValue />
902 <span aria-hidden="true">▼</span>
903 </Button>
904 <Popover>
905 <ListBox>
906 <ListBoxItem id="1">value</ListBoxItem>
907 </ListBox>
908 </Popover>
909 </Select>
910 <div data-testid="select-value">select value: {selectValue}</div>
911 </form>
912 );
913 }
914 let {getByTestId} = render(<Example />);
915 let selectValue = getByTestId('select-value');
916 expect(selectValue).toHaveTextContent('select value: 1');

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected