-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from kuhnroyal/fix/158-disposeProps
Fix disposeProps clearing all props even if predicate is provided.
- Loading branch information
Showing
2 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:async_redux/async_redux.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Add and dispose store properties', () { | ||
test('without dispose predicate', () async { | ||
final store = Store<int>(initialState: 1); | ||
|
||
final sub = Stream.periodic( | ||
const Duration(milliseconds: 10), | ||
(i) => i, | ||
).listen((event) {}); | ||
|
||
store.setProp( | ||
'future', | ||
Future.delayed( | ||
const Duration(seconds: 1), | ||
() => 'foo', | ||
), | ||
); | ||
store.setProp( | ||
'subscription', | ||
sub, | ||
); | ||
store.setProp('value', 'bar'); | ||
|
||
expect(store.props, hasLength(3)); | ||
|
||
store.disposeProps(); | ||
|
||
expect(store.props, hasLength(1)); | ||
expect(store.props.containsKey('value'), isTrue); | ||
}); | ||
|
||
test('with dispose predicate', () async { | ||
final store = Store<int>(initialState: 1); | ||
|
||
final sub = Stream.periodic( | ||
const Duration(milliseconds: 10), | ||
(i) => i, | ||
).listen((event) {}); | ||
|
||
store.setProp( | ||
'future', | ||
Future.delayed( | ||
const Duration(seconds: 1), | ||
() => 'foo', | ||
), | ||
); | ||
store.setProp( | ||
'subscription', | ||
sub, | ||
); | ||
store.setProp('value', 'bar'); | ||
|
||
expect(store.props, hasLength(3)); | ||
|
||
store.disposeProps(({key, value}) => key == 'value'); | ||
|
||
expect(store.props, hasLength(2)); | ||
expect(store.props.containsKey('value'), isFalse); | ||
}); | ||
}); | ||
} |