mock_event_channel 0.1.1+1 copy "mock_event_channel: ^0.1.1+1" to clipboard
mock_event_channel: ^0.1.1+1 copied to clipboard

discontinued

Temporary package to add support for mocking EventChannels in Flutter

NOTE: These changes are included in Flutter 3.13.0. This package is no longer needed.


Temporary package to add support for mocking EventChannels in Flutter

Features #

Adds setMockStreamHandler to TestDefaultBinaryMessenger with an extension

Usage #

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mock_event_channel/mock_event_channel.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  test('No arguments', () {
    const channel = EventChannel('mock_event_channel');
    TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
        .setMockStreamHandler(
      channel,
      MockStreamHandler.inline(
        onListen: (arguments, events) {
          events.success('asdf');
          events.error(code: 'asdf');
          events.endOfStream();
        },
      ),
    );

    final stream = channel.receiveBroadcastStream();
    expectLater(
      stream,
      emitsInOrder(
        [
          'asdf',
          emitsError(
            isA<PlatformException>().having((e) => e.code, 'code', 'asdf'),
          ),
          emitsDone
        ],
      ),
    );
  });
}

copied to clipboard

Additional information #

This package will be discontinued when this PR gets released to stable: https://github.com/flutter/flutter/pull/124415

This package is an exact copy of that code, so all you need to do when that PR is released is remove this package from your pubspec.

0
likes
90
points
16
downloads

Publisher

verified publisheriodesignteam.com

Weekly Downloads

2024.08.16 - 2025.02.28

Temporary package to add support for mocking EventChannels in Flutter

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_test

More

Packages that depend on mock_event_channel