state_notifier_test 0.0.4 copy "state_notifier_test: ^0.0.4" to clipboard
state_notifier_test: ^0.0.4 copied to clipboard

outdated

A testing library which makes it easy to test StateNotifier. Built to be used with the state_notifier, riverpod or flutter_riverpod packages.

example/main.dart

import 'package:state_notifier/state_notifier.dart';
import 'package:mockito/mockito.dart';
import 'package:state_notifier_test/state_notifier_test.dart';
import 'package:test/test.dart';

// Mock StateNotifier
class MockCounterStateNotifier extends Mock implements CounterStateNotifier {}

void main() {
  group('CounterStateNotifier', () {
    stateNotifierTest<CounterStateNotifier, int>(
      'emits [] when nothing is added',
      actions: (_) {},
      build: () => CounterStateNotifier(),
      expect: () => const <int>[],
    );

    stateNotifierTest<CounterStateNotifier, int>(
      'emits [1] when increment is called',
      build: () => CounterStateNotifier(),
      actions: (CounterStateNotifier notifier) => notifier.increment(),
      expect: () => const <int>[1],
    );
  });
}

class CounterStateNotifier extends StateNotifier<int> {
  CounterStateNotifier() : super(0);

  void increment() {
    state = state + 1;
  }
}
21
likes
0
pub points
79%
popularity

Publisher

verified publisherthat-dev.me

A testing library which makes it easy to test StateNotifier. Built to be used with the state_notifier, riverpod or flutter_riverpod packages.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

diff_match_patch, meta, mockito, state_notifier, test

More

Packages that depend on state_notifier_test