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

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
150
pub points
81%
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.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

diff_match_patch, meta, mockito, state_notifier, test

More

Packages that depend on state_notifier_test