@@ -2,6 +2,8 @@ import { fireEvent, render, screen } from "@testing-library/svelte";
2
2
import { userEvent } from "@testing-library/user-event" ;
3
3
import { describe , expect , it , vi } from "vitest" ;
4
4
import App from "./wrapper-components/use-focus.svelte" ;
5
+ import { useFloating , useId , useFocus } from '../../src/index.js' ;
6
+ import { withRunes } from '../internal/with-runes.svelte.js' ;
5
7
6
8
/**
7
9
* This test suite is skipped because `useFocus` heavily depends on the environment and JSDom can't deliver that environment (nor can happy-dom)
@@ -101,4 +103,40 @@ describe.skip("useFocus", () => {
101
103
expect ( screen . queryByTestId ( "floating" ) ) . toBeInTheDocument ( ) ;
102
104
} ) ;
103
105
} ) ;
106
+
107
+
104
108
} ) ;
109
+
110
+ describe ( "focusWithin" , ( ) => {
111
+ function createElements ( ) : { reference : HTMLElement ; floating : HTMLElement } {
112
+ const reference = document . createElement ( "div" ) ;
113
+ const floating = document . createElement ( "div" ) ;
114
+ reference . id = useId ( ) ;
115
+ floating . id = useId ( ) ;
116
+ return { reference, floating } ;
117
+ }
118
+
119
+ it ( "Should not output onfocusin or onfocusout event handlers" , withRunes ( ( ) => {
120
+ expect . assertions ( 2 ) ;
121
+
122
+ const elements = createElements ( ) ;
123
+ const floating = useFloating ( { elements } ) ;
124
+ const focus = useFocus ( floating . context ) ;
125
+ const handlers = focus . reference ;
126
+
127
+ expect ( handlers ) . not . toHaveProperty ( "onfocusin" ) ;
128
+ expect ( handlers ) . not . toHaveProperty ( "onfocusout" ) ;
129
+ } ) )
130
+
131
+ it ( "Should output onfocusin or onfocusout event handlers" , withRunes ( ( ) => {
132
+ expect . assertions ( 2 ) ;
133
+
134
+ const elements = createElements ( ) ;
135
+ const floating = useFloating ( { elements } ) ;
136
+ const focus = useFocus ( floating . context , { focusWithin : true } ) ;
137
+ const handlers = focus . reference ;
138
+
139
+ expect ( handlers ) . toHaveProperty ( "onfocusin" ) ;
140
+ expect ( handlers ) . toHaveProperty ( "onfocusout" ) ;
141
+ } ) )
142
+ } )
0 commit comments