vitest-native 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,10 @@ function reanimated() {
44
44
  "useDerivedValue",
45
45
  "useAnimatedScrollHandler",
46
46
  "useAnimatedGestureHandler",
47
+ "useAnimatedReaction",
48
+ "useAnimatedKeyboard",
49
+ "useReducedMotion",
50
+ "useFrameCallback",
47
51
  "withTiming",
48
52
  "withSpring",
49
53
  "withDecay",
@@ -56,15 +60,69 @@ function reanimated() {
56
60
  "Easing",
57
61
  "FadeIn",
58
62
  "FadeOut",
63
+ "FadeInDown",
64
+ "FadeInUp",
65
+ "FadeInLeft",
66
+ "FadeInRight",
67
+ "FadeOutDown",
68
+ "FadeOutUp",
69
+ "FadeOutLeft",
70
+ "FadeOutRight",
59
71
  "SlideInRight",
72
+ "SlideInLeft",
73
+ "SlideInUp",
74
+ "SlideInDown",
75
+ "SlideOutRight",
60
76
  "SlideOutLeft",
77
+ "SlideOutUp",
78
+ "SlideOutDown",
79
+ "ZoomIn",
80
+ "ZoomOut",
81
+ "BounceIn",
82
+ "BounceOut",
83
+ "BounceInDown",
84
+ "BounceInUp",
85
+ "BounceInLeft",
86
+ "BounceInRight",
87
+ "FlipInEasyX",
88
+ "FlipInEasyY",
89
+ "FlipOutEasyX",
90
+ "FlipOutEasyY",
91
+ "LightSpeedInLeft",
92
+ "LightSpeedInRight",
93
+ "LightSpeedOutLeft",
94
+ "LightSpeedOutRight",
95
+ "PinwheelIn",
96
+ "PinwheelOut",
97
+ "StretchInX",
98
+ "StretchInY",
99
+ "StretchOutX",
100
+ "StretchOutY",
101
+ "RotateInDownLeft",
102
+ "RotateInDownRight",
103
+ "RotateInUpLeft",
104
+ "RotateInUpRight",
105
+ "RotateOutDownLeft",
106
+ "RotateOutDownRight",
107
+ "RotateOutUpLeft",
108
+ "RotateOutUpRight",
61
109
  "Layout",
110
+ "LinearTransition",
111
+ "SequencedTransition",
112
+ "FadingTransition",
113
+ "JumpingTransition",
114
+ "CurvedTransition",
115
+ "EntryExitTransition",
62
116
  "interpolate",
63
117
  "Extrapolation",
64
118
  "useAnimatedRef",
65
119
  "measure",
66
120
  "scrollTo",
67
- "cancelAnimation"
121
+ "cancelAnimation",
122
+ "makeMutable",
123
+ "SharedTransition",
124
+ "ReduceMotion",
125
+ "KeyboardState"
68
126
  ],
69
127
  factory: () => {
70
128
  function createSharedValue(init) {
@@ -109,6 +167,23 @@ function reanimated() {
109
167
  function useAnimatedGestureHandler(_handler) {
110
168
  return vitest.vi.fn();
111
169
  }
170
+ function useAnimatedReaction(_prepare, _react, _deps) {}
171
+ function useAnimatedKeyboard() {
172
+ return {
173
+ state: createSharedValue(0),
174
+ height: createSharedValue(0)
175
+ };
176
+ }
177
+ function useReducedMotion() {
178
+ return false;
179
+ }
180
+ function useFrameCallback(_callback, _autostart) {
181
+ return {
182
+ setActive: vitest.vi.fn(),
183
+ isActive: false,
184
+ callbackId: 0
185
+ };
186
+ }
112
187
  function withTiming(toValue, _config, callback) {
113
188
  callback?.({
114
189
  finished: true,
@@ -155,6 +230,24 @@ function reanimated() {
155
230
  Animated.displayName = `Animated(${component.displayName || component.name || "Component"})`;
156
231
  return Animated;
157
232
  }
233
+ function createLayoutAnim() {
234
+ const obj = {};
235
+ obj.duration = vitest.vi.fn().mockReturnValue(obj);
236
+ obj.delay = vitest.vi.fn().mockReturnValue(obj);
237
+ obj.easing = vitest.vi.fn().mockReturnValue(obj);
238
+ obj.damping = vitest.vi.fn().mockReturnValue(obj);
239
+ obj.stiffness = vitest.vi.fn().mockReturnValue(obj);
240
+ obj.mass = vitest.vi.fn().mockReturnValue(obj);
241
+ obj.overshootClamping = vitest.vi.fn().mockReturnValue(obj);
242
+ obj.restDisplacementThreshold = vitest.vi.fn().mockReturnValue(obj);
243
+ obj.restSpeedThreshold = vitest.vi.fn().mockReturnValue(obj);
244
+ obj.springify = vitest.vi.fn().mockReturnValue(obj);
245
+ obj.withCallback = vitest.vi.fn().mockReturnValue(obj);
246
+ obj.withInitialValues = vitest.vi.fn().mockReturnValue(obj);
247
+ obj.randomDelay = vitest.vi.fn().mockReturnValue(obj);
248
+ obj.build = vitest.vi.fn();
249
+ return obj;
250
+ }
158
251
  return {
159
252
  default: { createAnimatedComponent },
160
253
  useSharedValue,
@@ -163,6 +256,10 @@ function reanimated() {
163
256
  useDerivedValue,
164
257
  useAnimatedScrollHandler,
165
258
  useAnimatedGestureHandler,
259
+ useAnimatedReaction,
260
+ useAnimatedKeyboard,
261
+ useReducedMotion,
262
+ useFrameCallback,
166
263
  withTiming,
167
264
  withSpring,
168
265
  withDecay,
@@ -182,28 +279,61 @@ function reanimated() {
182
279
  out: vitest.vi.fn((fn) => fn),
183
280
  inOut: vitest.vi.fn((fn) => fn)
184
281
  },
185
- FadeIn: {
186
- duration: vitest.vi.fn().mockReturnThis(),
187
- delay: vitest.vi.fn().mockReturnThis(),
188
- build: vitest.vi.fn()
189
- },
190
- FadeOut: {
191
- duration: vitest.vi.fn().mockReturnThis(),
192
- delay: vitest.vi.fn().mockReturnThis(),
193
- build: vitest.vi.fn()
194
- },
195
- SlideInRight: {
196
- duration: vitest.vi.fn().mockReturnThis(),
197
- build: vitest.vi.fn()
198
- },
199
- SlideOutLeft: {
200
- duration: vitest.vi.fn().mockReturnThis(),
201
- build: vitest.vi.fn()
202
- },
203
- Layout: {
204
- duration: vitest.vi.fn().mockReturnThis(),
205
- build: vitest.vi.fn()
206
- },
282
+ FadeIn: createLayoutAnim(),
283
+ FadeOut: createLayoutAnim(),
284
+ FadeInDown: createLayoutAnim(),
285
+ FadeInUp: createLayoutAnim(),
286
+ FadeInLeft: createLayoutAnim(),
287
+ FadeInRight: createLayoutAnim(),
288
+ FadeOutDown: createLayoutAnim(),
289
+ FadeOutUp: createLayoutAnim(),
290
+ FadeOutLeft: createLayoutAnim(),
291
+ FadeOutRight: createLayoutAnim(),
292
+ SlideInRight: createLayoutAnim(),
293
+ SlideInLeft: createLayoutAnim(),
294
+ SlideInUp: createLayoutAnim(),
295
+ SlideInDown: createLayoutAnim(),
296
+ SlideOutRight: createLayoutAnim(),
297
+ SlideOutLeft: createLayoutAnim(),
298
+ SlideOutUp: createLayoutAnim(),
299
+ SlideOutDown: createLayoutAnim(),
300
+ ZoomIn: createLayoutAnim(),
301
+ ZoomOut: createLayoutAnim(),
302
+ BounceIn: createLayoutAnim(),
303
+ BounceOut: createLayoutAnim(),
304
+ BounceInDown: createLayoutAnim(),
305
+ BounceInUp: createLayoutAnim(),
306
+ BounceInLeft: createLayoutAnim(),
307
+ BounceInRight: createLayoutAnim(),
308
+ FlipInEasyX: createLayoutAnim(),
309
+ FlipInEasyY: createLayoutAnim(),
310
+ FlipOutEasyX: createLayoutAnim(),
311
+ FlipOutEasyY: createLayoutAnim(),
312
+ LightSpeedInLeft: createLayoutAnim(),
313
+ LightSpeedInRight: createLayoutAnim(),
314
+ LightSpeedOutLeft: createLayoutAnim(),
315
+ LightSpeedOutRight: createLayoutAnim(),
316
+ PinwheelIn: createLayoutAnim(),
317
+ PinwheelOut: createLayoutAnim(),
318
+ StretchInX: createLayoutAnim(),
319
+ StretchInY: createLayoutAnim(),
320
+ StretchOutX: createLayoutAnim(),
321
+ StretchOutY: createLayoutAnim(),
322
+ RotateInDownLeft: createLayoutAnim(),
323
+ RotateInDownRight: createLayoutAnim(),
324
+ RotateInUpLeft: createLayoutAnim(),
325
+ RotateInUpRight: createLayoutAnim(),
326
+ RotateOutDownLeft: createLayoutAnim(),
327
+ RotateOutDownRight: createLayoutAnim(),
328
+ RotateOutUpLeft: createLayoutAnim(),
329
+ RotateOutUpRight: createLayoutAnim(),
330
+ Layout: createLayoutAnim(),
331
+ LinearTransition: createLayoutAnim(),
332
+ SequencedTransition: createLayoutAnim(),
333
+ FadingTransition: createLayoutAnim(),
334
+ JumpingTransition: createLayoutAnim(),
335
+ CurvedTransition: createLayoutAnim(),
336
+ EntryExitTransition: createLayoutAnim(),
207
337
  interpolate: vitest.vi.fn((_value, input, output) => output[0]),
208
338
  Extrapolation: {
209
339
  CLAMP: "clamp",
@@ -220,7 +350,26 @@ function reanimated() {
220
350
  pageY: 0
221
351
  })),
222
352
  scrollTo: vitest.vi.fn(),
223
- cancelAnimation: vitest.vi.fn()
353
+ cancelAnimation: vitest.vi.fn(),
354
+ makeMutable: vitest.vi.fn((init) => createSharedValue(init)),
355
+ SharedTransition: {
356
+ duration: vitest.vi.fn().mockReturnThis(),
357
+ custom: vitest.vi.fn().mockReturnThis(),
358
+ progressAnimation: vitest.vi.fn().mockReturnThis(),
359
+ defaultTransitionType: vitest.vi.fn().mockReturnThis()
360
+ },
361
+ ReduceMotion: {
362
+ System: "system",
363
+ Always: "always",
364
+ Never: "never"
365
+ },
366
+ KeyboardState: {
367
+ UNKNOWN: 0,
368
+ OPENING: 1,
369
+ OPEN: 2,
370
+ CLOSING: 3,
371
+ CLOSED: 4
372
+ }
224
373
  };
225
374
  }
226
375
  } }
@@ -399,19 +548,25 @@ function safeAreaContext() {
399
548
  "Metrics"
400
549
  ],
401
550
  factory: () => {
551
+ const defaultInsets = {
552
+ top: 47,
553
+ right: 0,
554
+ bottom: 34,
555
+ left: 0
556
+ };
557
+ const defaultFrame = {
558
+ x: 0,
559
+ y: 0,
560
+ width: 390,
561
+ height: 844
562
+ };
563
+ const state = {
564
+ insets: { ...defaultInsets },
565
+ frame: { ...defaultFrame }
566
+ };
402
567
  const initialMetrics = {
403
- frame: {
404
- x: 0,
405
- y: 0,
406
- width: 390,
407
- height: 844
408
- },
409
- insets: {
410
- top: 47,
411
- right: 0,
412
- bottom: 34,
413
- left: 0
414
- }
568
+ frame: state.frame,
569
+ insets: state.insets
415
570
  };
416
571
  const SafeAreaProvider = react.default.forwardRef((props, ref) => react.default.createElement("SafeAreaProvider", {
417
572
  ...props,
@@ -423,19 +578,19 @@ function safeAreaContext() {
423
578
  ref
424
579
  }, props.children));
425
580
  SafeAreaView.displayName = "SafeAreaView";
426
- const SafeAreaInsetsContext = react.default.createContext(initialMetrics.insets);
427
- const SafeAreaFrameContext = react.default.createContext(initialMetrics.frame);
581
+ const SafeAreaInsetsContext = react.default.createContext(state.insets);
582
+ const SafeAreaFrameContext = react.default.createContext(state.frame);
428
583
  function useSafeAreaInsets() {
429
- return initialMetrics.insets;
584
+ return state.insets;
430
585
  }
431
586
  function useSafeAreaFrame() {
432
- return initialMetrics.frame;
587
+ return state.frame;
433
588
  }
434
589
  function withSafeAreaInsets(WrappedComponent) {
435
590
  const WithSafeAreaInsets = react.default.forwardRef((props, ref) => react.default.createElement(WrappedComponent, {
436
591
  ...props,
437
592
  ref,
438
- insets: initialMetrics.insets
593
+ insets: state.insets
439
594
  }));
440
595
  WithSafeAreaInsets.displayName = `withSafeAreaInsets(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
441
596
  return WithSafeAreaInsets;
@@ -453,10 +608,17 @@ function safeAreaContext() {
453
608
  useSafeAreaFrame,
454
609
  withSafeAreaInsets,
455
610
  initialWindowMetrics: initialMetrics,
456
- initialWindowSafeAreaInsets: initialMetrics.insets,
611
+ initialWindowSafeAreaInsets: state.insets,
457
612
  EdgeInsets: vitest.vi.fn(),
458
613
  Rect: vitest.vi.fn(),
459
- Metrics: vitest.vi.fn()
614
+ Metrics: vitest.vi.fn(),
615
+ _setInsets: (insets) => {
616
+ Object.assign(state.insets, insets);
617
+ },
618
+ _reset: () => {
619
+ Object.assign(state.insets, defaultInsets);
620
+ Object.assign(state.frame, defaultFrame);
621
+ }
460
622
  };
461
623
  }
462
624
  } }
@@ -464,7 +626,76 @@ function safeAreaContext() {
464
626
  }
465
627
  //#endregion
466
628
  //#region src/presets/navigation.ts
629
+ /** Builds a minimal navigation prop matching useNavigation()'s shape. */
630
+ function createMockNavigation() {
631
+ return {
632
+ navigate: vitest.vi.fn(),
633
+ goBack: vitest.vi.fn(),
634
+ reset: vitest.vi.fn(),
635
+ setParams: vitest.vi.fn(),
636
+ setOptions: vitest.vi.fn(),
637
+ dispatch: vitest.vi.fn(),
638
+ canGoBack: vitest.vi.fn(() => false),
639
+ getParent: vitest.vi.fn(() => void 0),
640
+ getState: vitest.vi.fn(() => ({
641
+ index: 0,
642
+ key: "root",
643
+ routeNames: [],
644
+ routes: [],
645
+ type: "stack",
646
+ stale: false
647
+ })),
648
+ isFocused: vitest.vi.fn(() => true),
649
+ addListener: vitest.vi.fn(() => vitest.vi.fn()),
650
+ removeListener: vitest.vi.fn(),
651
+ getId: vitest.vi.fn(() => void 0)
652
+ };
653
+ }
654
+ /**
655
+ * Creates a Screen component mock that handles all three React Navigation patterns:
656
+ * 1. <Screen component={Comp} /> — renders Comp with route & navigation props
657
+ * 2. <Screen>{(props) => <Comp />}</Screen> — calls render function
658
+ * 3. <Screen><Something /></Screen> — passes children through
659
+ *
660
+ * Accepts NavigationContext and NavigationRouteContext so that hooks like
661
+ * useNavigation() and useRoute() inside the screen component return values
662
+ * consistent with the route/navigation props passed to the component.
663
+ */
664
+ function createMockScreen(NavContext, RouteContext) {
665
+ const Screen = react.default.forwardRef(({ component: Component, children, ...rest }, ref) => {
666
+ const route = {
667
+ key: rest.name ?? "",
668
+ name: rest.name ?? "",
669
+ params: rest.initialParams
670
+ };
671
+ const nav = createMockNavigation();
672
+ const content = Component ? react.default.createElement(Component, {
673
+ route,
674
+ navigation: nav
675
+ }) : typeof children === "function" ? children({
676
+ route,
677
+ navigation: nav
678
+ }) : children;
679
+ return react.default.createElement("Screen", {
680
+ ...rest,
681
+ ref
682
+ }, react.default.createElement(NavContext.Provider, { value: nav }, react.default.createElement(RouteContext.Provider, { value: route }, content)));
683
+ });
684
+ Screen.displayName = "Screen";
685
+ return Screen;
686
+ }
467
687
  function navigation() {
688
+ const NavigationContext = react.default.createContext(null);
689
+ const NavigationRouteContext = react.default.createContext(null);
690
+ const NavigationContainerRefContext = react.default.createContext(null);
691
+ const NavigationHelpersContext = react.default.createContext(null);
692
+ const CurrentRenderContext = react.default.createContext(void 0);
693
+ const ThemeContext = react.default.createContext({
694
+ dark: false,
695
+ colors: {}
696
+ });
697
+ const PreventRemoveContext = react.default.createContext(null);
698
+ const Screen = createMockScreen(NavigationContext, NavigationRouteContext);
468
699
  return {
469
700
  name: "navigation",
470
701
  modules: {
@@ -478,6 +709,7 @@ function navigation() {
478
709
  "useFocusEffect",
479
710
  "useIsFocused",
480
711
  "useNavigationState",
712
+ "useScrollToTop",
481
713
  "useNavigationContainerRef",
482
714
  "createNavigationContainerRef",
483
715
  "createNavigatorFactory",
@@ -534,29 +766,39 @@ function navigation() {
534
766
  type: "stack",
535
767
  stale: false
536
768
  }));
769
+ const defaultNavigation = {
770
+ navigate,
771
+ goBack,
772
+ reset,
773
+ setParams,
774
+ setOptions,
775
+ dispatch,
776
+ canGoBack,
777
+ getParent,
778
+ getState,
779
+ isFocused: vitest.vi.fn(() => true),
780
+ addListener: vitest.vi.fn(() => vitest.vi.fn()),
781
+ removeListener: vitest.vi.fn(),
782
+ getId: vitest.vi.fn(() => void 0)
783
+ };
784
+ const defaultRoute = {
785
+ key: "test-route-key",
786
+ name: "TestScreen",
787
+ params: {}
788
+ };
537
789
  function useNavigation() {
538
- return {
539
- navigate,
540
- goBack,
541
- reset,
542
- setParams,
543
- setOptions,
544
- dispatch,
545
- canGoBack,
546
- getParent,
547
- getState,
548
- isFocused: vitest.vi.fn(() => true),
549
- addListener: vitest.vi.fn(() => vitest.vi.fn()),
550
- removeListener: vitest.vi.fn(),
551
- getId: vitest.vi.fn(() => void 0)
552
- };
790
+ try {
791
+ const ctx = react.default.useContext(NavigationContext);
792
+ if (ctx) return ctx;
793
+ } catch {}
794
+ return defaultNavigation;
553
795
  }
554
796
  function useRoute() {
555
- return {
556
- key: "test-route-key",
557
- name: "TestScreen",
558
- params: {}
559
- };
797
+ try {
798
+ const ctx = react.default.useContext(NavigationRouteContext);
799
+ if (ctx) return ctx;
800
+ } catch {}
801
+ return defaultRoute;
560
802
  }
561
803
  function useFocusEffect(callback) {
562
804
  react.default.useEffect(callback, []);
@@ -589,16 +831,6 @@ function navigation() {
589
831
  function useNavigationContainerRef() {
590
832
  return createNavigationContainerRef();
591
833
  }
592
- const NavigationContext = react.default.createContext(null);
593
- const NavigationRouteContext = react.default.createContext(null);
594
- const NavigationContainerRefContext = react.default.createContext(null);
595
- const NavigationHelpersContext = react.default.createContext(null);
596
- const CurrentRenderContext = react.default.createContext(void 0);
597
- const ThemeContext = react.default.createContext({
598
- dark: false,
599
- colors: {}
600
- });
601
- const PreventRemoveContext = react.default.createContext(null);
602
834
  const defaultTheme = {
603
835
  dark: false,
604
836
  colors: {
@@ -698,6 +930,7 @@ function navigation() {
698
930
  getStateForAction: vitest.vi.fn((state) => state),
699
931
  shouldActionChangeFocus: vitest.vi.fn(() => false)
700
932
  },
933
+ useScrollToTop: vitest.vi.fn(),
701
934
  useLinkTo: vitest.vi.fn(() => vitest.vi.fn()),
702
935
  Link: react.default.forwardRef((props, ref) => react.default.createElement("Link", {
703
936
  ...props,
@@ -715,10 +948,7 @@ function navigation() {
715
948
  ...props,
716
949
  ref
717
950
  }, props.children)),
718
- Screen: react.default.forwardRef((props, ref) => react.default.createElement("Screen", {
719
- ...props,
720
- ref
721
- }, props.children)),
951
+ Screen,
722
952
  Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
723
953
  ...props,
724
954
  ref
@@ -740,10 +970,29 @@ function navigation() {
740
970
  ...props,
741
971
  ref
742
972
  }, props.children)),
743
- Screen: react.default.forwardRef((props, ref) => react.default.createElement("Screen", {
973
+ Screen,
974
+ Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
975
+ ...props,
976
+ ref
977
+ }, props.children))
978
+ };
979
+ }
980
+ return {
981
+ default: { createBottomTabNavigator },
982
+ createBottomTabNavigator
983
+ };
984
+ }
985
+ },
986
+ "@react-navigation/drawer": {
987
+ exports: ["createDrawerNavigator"],
988
+ factory: () => {
989
+ function createDrawerNavigator() {
990
+ return {
991
+ Navigator: react.default.forwardRef((props, ref) => react.default.createElement("DrawerNavigator", {
744
992
  ...props,
745
993
  ref
746
994
  }, props.children)),
995
+ Screen,
747
996
  Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
748
997
  ...props,
749
998
  ref
@@ -751,8 +1000,8 @@ function navigation() {
751
1000
  };
752
1001
  }
753
1002
  return {
754
- default: { createBottomTabNavigator },
755
- createBottomTabNavigator
1003
+ default: { createDrawerNavigator },
1004
+ createDrawerNavigator
756
1005
  };
757
1006
  }
758
1007
  },
@@ -887,7 +1136,8 @@ function asyncStorage() {
887
1136
  else store.set(key, value);
888
1137
  });
889
1138
  }),
890
- flushGetRequests: vitest.vi.fn(() => {})
1139
+ flushGetRequests: vitest.vi.fn(() => {}),
1140
+ _resetStore: () => store.clear()
891
1141
  };
892
1142
  return {
893
1143
  ...exports,