StoreTester<St> constructor

StoreTester<St>({
  1. required St initialState,
  2. TestInfoPrinter? testInfoPrinter,
  3. List<Type>? ignore,
  4. bool syncStream = false,
  5. ErrorObserver<St>? errorObserver,
  6. bool shouldThrowUserExceptions = false,
  7. Map<Type, dynamic>? mocks,
})

The StoreTester makes it easy to test both sync and async reducers. You may dispatch some action, wait for it to finish or wait until some arbitrary condition is met, and then check the resulting state.

The StoreTester will, by default, print some default debug information to the console. You can disable these prints globally by making StoreTester.printDefaultDebugInfo = false. Note you can also provide your own custom testInfoPrinter.

If shouldThrowUserExceptions is true, all errors will be thrown, and not swallowed, including UserExceptions. Use this in all tests that should throw no errors. Pass shouldThrowUserExceptions as false when you are testing code that should throw UserExceptions. These exceptions will then silently go to the errors queue, where you can assert they exist with the right error messages.

Implementation

StoreTester({
  required St initialState,
  TestInfoPrinter? testInfoPrinter,
  List<Type>? ignore,
  bool syncStream = false,
  ErrorObserver<St>? errorObserver,
  bool shouldThrowUserExceptions = false,
  Map<Type, dynamic>? mocks,
}) : this.from(
          MockStore(
            initialState: initialState,
            syncStream: syncStream,
            errorObserver: errorObserver ?? //
                (shouldThrowUserExceptions ? TestErrorObserver() : null),
            mocks: mocks,
          ),
          testInfoPrinter: testInfoPrinter,
          ignore: ignore);