@@ -3,6 +3,27 @@ import buildNetworkInformationUtils, {
33 NetworkInformationUtils ,
44} from "./network-information-utils" ;
55
6+ const buildMockWindow = ( navigator ?: Navigator ) => {
7+ return { navigator } as Window & typeof globalThis ;
8+ } ;
9+
10+ const buildMockNavigator = (
11+ connectionProperty ?: string ,
12+ onLine : boolean = false
13+ ) : Navigator => {
14+ const isOnline = onLine ?? navigator . onLine ;
15+
16+ if ( connectionProperty != null ) {
17+ return {
18+ ...navigator ,
19+ onLine : isOnline ,
20+ [ connectionProperty ] : { } ,
21+ } ;
22+ }
23+
24+ return { ...navigator , onLine : isOnline } ;
25+ } ;
26+
627const setupSut = ( options ?: {
728 buildNavigator ?: boolean ;
829 buildWindow ?: boolean ;
@@ -16,22 +37,11 @@ const setupSut = (options?: {
1637 onLine = false ,
1738 } = options ?? { } ;
1839
19- const buildMockNavigator = ( ) : Navigator => {
20- const isOnline = onLine ?? navigator . onLine ;
21-
22- if ( connectionProperty != null ) {
23- return {
24- ...navigator ,
25- onLine : isOnline ,
26- [ connectionProperty ] : { } ,
27- } ;
28- }
29-
30- return { ...navigator , onLine : isOnline } ;
31- } ;
40+ const navigator = buildNavigator
41+ ? buildMockNavigator ( connectionProperty , onLine )
42+ : undefined ;
3243
33- const navigator = buildNavigator ? buildMockNavigator ( ) : undefined ;
34- const window = buildWindow ? ( { navigator } as Window ) : undefined ;
44+ const window = buildWindow ? buildMockWindow ( navigator ) : undefined ;
3545
3646 return buildNetworkInformationUtils ( window ) ;
3747} ;
0 commit comments