Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

IO-Design-Team/mock_event_channel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
        ],
      ),
    );
  });
}

Additional information

This package will be discontinued when this PR gets released to stable: flutter/flutter#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.

About

Temporary package to add support for mocking EventChannels in Flutter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages