From 8a37dcb32195eb69152371950633aa7d101d0885 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Mon, 20 Nov 2023 15:55:50 -0700 Subject: [PATCH] Fix useSelector nullability, beef up test expectation --- lib/src/over_react_redux/hooks/use_selector.dart | 2 +- test/over_react_redux/fixtures/counter_fn.dart | 4 ++-- .../fixtures/counter_fn.over_react.g.dart | 13 ++++++------- test/over_react_redux/store_bindings_tests.dart | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/src/over_react_redux/hooks/use_selector.dart b/lib/src/over_react_redux/hooks/use_selector.dart index f79f46328..56c4ca54e 100644 --- a/lib/src/over_react_redux/hooks/use_selector.dart +++ b/lib/src/over_react_redux/hooks/use_selector.dart @@ -129,7 +129,7 @@ import 'package:react/react_client/react_interop.dart' show ReactContext; /// > Related: [useDispatch] TValue useSelector( TValue Function(TReduxState state) selector, [ - bool Function(TValue? tNextValue, TValue? tPrevValue)? equalityFn, + bool Function(TValue tNextValue, TValue tPrevValue)? equalityFn, ]) { Object? /*[1]*/ jsSelector(Object? /*[1]*/ jsState) => DartValueWrapper.wrapIfNeeded(selector(DartValueWrapper.unwrapIfNeeded(jsState))); diff --git a/test/over_react_redux/fixtures/counter_fn.dart b/test/over_react_redux/fixtures/counter_fn.dart index b0ed88def..7e58bf6c7 100644 --- a/test/over_react_redux/fixtures/counter_fn.dart +++ b/test/over_react_redux/fixtures/counter_fn.dart @@ -23,7 +23,7 @@ import 'store.dart'; part 'counter_fn.over_react.g.dart'; mixin CounterFnProps on UiProps { - bool Function(int? nextCount, int? prevCount)? countEqualityFn; + bool Function(int nextCount, int prevCount)? countEqualityFn; } UiFactory CounterFn = uiFunction( @@ -43,7 +43,7 @@ UiFactory CounterFn = uiFunction( ); mixin ModelCounterFnPropsMixin on UiProps { - bool Function(DartModelCounter? nextCount, DartModelCounter? prevCount)? modelCountEqualityFn; + bool Function(DartModelCounter nextCount, DartModelCounter prevCount)? modelCountEqualityFn; } class ModelCounterFnProps = UiProps with CounterFnProps, ModelCounterFnPropsMixin; diff --git a/test/over_react_redux/fixtures/counter_fn.over_react.g.dart b/test/over_react_redux/fixtures/counter_fn.over_react.g.dart index b14282c08..b162d752e 100644 --- a/test/over_react_redux/fixtures/counter_fn.over_react.g.dart +++ b/test/over_react_redux/fixtures/counter_fn.over_react.g.dart @@ -14,11 +14,11 @@ part of 'counter_fn.dart'; mixin $CounterFnProps on CounterFnProps { static const PropsMeta meta = _$metaForCounterFnProps; @override - bool Function(int? nextCount, int? prevCount)? get countEqualityFn => + bool Function(int nextCount, int prevCount)? get countEqualityFn => (props[_$key__countEqualityFn__CounterFnProps] ?? null) as bool Function( - int? nextCount, int? prevCount)?; + int nextCount, int prevCount)?; @override - set countEqualityFn(bool Function(int? nextCount, int? prevCount)? value) => + set countEqualityFn(bool Function(int nextCount, int prevCount)? value) => props[_$key__countEqualityFn__CounterFnProps] = value; /* GENERATED CONSTANTS */ static const PropDescriptor _$prop__countEqualityFn__CounterFnProps = @@ -48,15 +48,14 @@ const PropsMeta _$metaForCounterFnProps = PropsMeta( mixin $ModelCounterFnPropsMixin on ModelCounterFnPropsMixin { static const PropsMeta meta = _$metaForModelCounterFnPropsMixin; @override - bool Function(DartModelCounter? nextCount, DartModelCounter? prevCount)? + bool Function(DartModelCounter nextCount, DartModelCounter prevCount)? get modelCountEqualityFn => (props[_$key__modelCountEqualityFn__ModelCounterFnPropsMixin] ?? null) as bool Function( - DartModelCounter? nextCount, DartModelCounter? prevCount)?; + DartModelCounter nextCount, DartModelCounter prevCount)?; @override set modelCountEqualityFn( - bool Function( - DartModelCounter? nextCount, DartModelCounter? prevCount)? + bool Function(DartModelCounter nextCount, DartModelCounter prevCount)? value) => props[_$key__modelCountEqualityFn__ModelCounterFnPropsMixin] = value; /* GENERATED CONSTANTS */ diff --git a/test/over_react_redux/store_bindings_tests.dart b/test/over_react_redux/store_bindings_tests.dart index 406109dc4..9de074202 100644 --- a/test/over_react_redux/store_bindings_tests.dart +++ b/test/over_react_redux/store_bindings_tests.dart @@ -191,6 +191,20 @@ void sharedSelectorHookAndConnectTests( 'prev': same(initialValue), })), reason: 'should have been called with the next and previous values, properly unwrapped'); + expect(calls, everyElement(anyOf([ + equals({ + 'next': same(updatedValue1), + 'prev': same(initialValue), + }), + equals({ + 'next': same(initialValue), + 'prev': same(initialValue), + }), + equals({ + 'next': same(updatedValue1), + 'prev': same(updatedValue1), + }), + ])), reason: 'should only have been called with expected next/prev value pairings'); }); test('unless a custom equalityFn returns true', () async {