puer_test 1.0.0 copy "puer_test: ^1.0.0" to clipboard
puer_test: ^1.0.0 copied to clipboard

A package to make feature testing in puer easier and more enjoyable.

Puer Test #

Puer

Pub License: MIT


Testing utilities for puer — concise, assertion-style tests for update functions and EffectHandlers.


Features #

Concise update tests — Test your pure update function with a single .test() call
Handler testing — Verify effect handlers emit the correct messages
No boilerplate — No manual stream subscriptions, no async coordination
Clear assertions — Expected state and effects are explicit parameters


Installation #

dev_dependencies:
  puer_test: ^1.0.0

Testing update functions #

Since update is a pure function, testing is straightforward — call it with a state and message, verify the result.

Example:

import 'package:puer_test/puer_test.dart';
import 'package:test/test.dart';

void main() {
  test('Increment increases count by 1', () {
    counterUpdate.test(
      state: const CounterState(count: 5),
      message: Increment(),
      expectedState: const CounterState(count: 6),
    );
  });

  test('LoadTodos sets loading flag and emits FetchTodos effect', () {
    todoUpdate.test(
      state: const TodoState(todos: [], isLoading: false),
      message: LoadTodos(),
      expectedState: const TodoState(todos: [], isLoading: true),
      expectedEffects: [FetchTodos()],
    );
  });
}

Parameters:

Parameter Description
state The current state before the message
message The message to process
expectedState The expected state after processing (optional if no state change)
expectedEffects The expected list of effects (optional if no effects)

Testing EffectHandlers #

Effect handlers require mocks for their dependencies. This example uses mocktail.

Example:

import 'package:mocktail/mocktail.dart';
import 'package:puer_test/puer_test.dart';
import 'package:test/test.dart';

class MockTodoRepository extends Mock implements TodoRepository {}

void main() {
  test('FetchTodosHandler emits TodosLoaded on success', () async {
    final mockRepo = MockTodoRepository();
    when(() => mockRepo.fetchAll()).thenAnswer(
      (_) async => ['Task 1', 'Task 2'],
    );

    final handler = FetchTodosHandler(mockRepo);

    await handler.test(
      effect: FetchTodos(),
      expectedMessages: [TodosLoaded(['Task 1', 'Task 2'])],
    );
  });

  test('FetchTodosHandler emits TodosLoadFailed on error', () async {
    final mockRepo = MockTodoRepository();
    when(() => mockRepo.fetchAll()).thenThrow(Exception('Network error'));

    final handler = FetchTodosHandler(mockRepo);

    await handler.test(
      effect: FetchTodos(),
      expectedMessages: [TodosLoadFailed()],
    );
  });
}

Parameters:

Parameter Description
effect The effect to process
expectedMessages The expected list of messages emitted by the handler

Why test with puer_test? #

Without puer_test:

test('Increment increases count', () {
  final result = counterUpdate(
    const CounterState(count: 5),
    Increment(),
  );
  
  expect(result.state, equals(const CounterState(count: 6)));
  expect(result.effects, isEmpty);
});

With puer_test:

test('Increment increases count', () {
  counterUpdate.test(
    state: const CounterState(count: 5),
    message: Increment(),
    expectedState: const CounterState(count: 6),
  );
});

Less noise, clearer intent.


Packages #

Package Pub Description
puer pub package Core TEA implementation with Feature, update, and effect handlers. Pure Dart foundation.
puer_flutter pub package Flutter integration: FeatureProvider, FeatureBuilder, FeatureListener widgets.
puer_effect_handlers pub package Composable wrappers for debouncing, sequential execution, and isolate offloading.
puer_test pub package Testing utilities for concise update and handler tests. Add to dev_dependencies.
puer_time_travel pub package Time-travel debugging with DevTools extension. Use in debug builds to inspect history.

Learn more #


License #

MIT

1
likes
160
points
195
downloads

Documentation

API reference

Publisher

verified publishervorky.io

Weekly Downloads

A package to make feature testing in puer easier and more enjoyable.

Homepage
Repository (GitHub)
View/report issues

Topics

#state-management #architecture #unidirectional-data-flow #mvi #tea

License

MIT (license)

Dependencies

meta, puer, test

More

Packages that depend on puer_test