Skip to content

Commit

Permalink
Fix useSelector nullability, beef up test expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Nov 20, 2023
1 parent 468b948 commit 1cd4cd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/src/over_react_redux/hooks/use_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import 'package:react/react_client/react_interop.dart' show ReactContext;
/// > Related: [useDispatch]
TValue useSelector<TReduxState, TValue>(
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)));
Expand Down
4 changes: 2 additions & 2 deletions test/over_react_redux/fixtures/counter_fn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<CounterFnProps> CounterFn = uiFunction(
Expand All @@ -43,7 +43,7 @@ UiFactory<CounterFnProps> 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;
Expand Down
13 changes: 6 additions & 7 deletions test/over_react_redux/fixtures/counter_fn.over_react.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/over_react_redux/store_bindings_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:math';

import 'package:js/js.dart';
import 'package:meta/meta.dart';
import 'package:over_react/over_react.dart';
Expand Down Expand Up @@ -191,6 +193,20 @@ void sharedSelectorHookAndConnectTests<T extends Object?>(
'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 {
Expand Down

0 comments on commit 1cd4cd1

Please sign in to comment.