riverpod_testing_library 0.1.0 copy "riverpod_testing_library: ^0.1.0" to clipboard
riverpod_testing_library: ^0.1.0 copied to clipboard

outdated

A testing library which makes it easy to test providers. Built to be used with the riverpod state management package.

Riverpod Testing Library #

style: very good analysis License: MIT

A testing library which makes it easy to test providers. Built to be used with the riverpod state management package. Inspired by bloc_test.

Getting started #

Add riverpod_testing_library to your pubspec.yaml:

dev_dependencies:
  riverpod_testing_library: 0.1.0

Install it:

dart pub get

Usage examples #

Write unit tests with providerTest #

providerTest creates a new provider-specific tests case. It will handle asserting that the provider updates with the expected states (in order). It also handles ensuring that no additional states are stored by disposing the container being used in a test.

group('counterProvider', () {
  providerTest<int>(
    'emits the initial state when fireImmediately is true',
    provider: counterProvider,
    fireImmediately: true,
    expect: () => [0],
  );

  providerTest<int>(
    'emits [] when nothing is done',
    provider: counterProvider,
    expect: () => [],
  );

  providerTest<int>(
    'emits [1] when Counter.increment() is called',
    provider: counterProvider,
    act: (container) => container.read(counterProvider.notifier).increment(),
    expect: () => [1],
  );
});

When using providerTest with state classes which don't override == and hashCode you can provide an Iterable of matchers instead of explicit state instances.

providerTest<int>(
  'emits [1] when Counter.increment() is called',
  provider: counterProvider,
  act: (container) => container.read(counterProvider.notifier).increment(),
  expect: () => [
    predicate<int>((value) {
      expect(value, 1);

      return true;
    }),
  ],
);
5
likes
0
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

A testing library which makes it easy to test providers. Built to be used with the riverpod state management package.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

diff_match_patch, meta, mocktail, riverpod, riverpod_annotation, riverpod_generator, test

More

Packages that depend on riverpod_testing_library