koukibadr / Motion-Toast

Home Page:https://pub.dev/packages/motion_toast

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I test the title / description that is displayed in the motion toast in a Widget testing

DiegoVega19 opened this issue · comments

Can you provide please any example of how to test, the title / description that is displayed in the motion toast?

Here is my code that doesnt work.

My Widget Test.
void main() {
  testWidgets('MotionToast text title / description',
      (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(MaterialApp(home: Material(
      child: Builder(
        builder: (BuildContext context) {
          return Center(
            child: ElevatedButton(
              child: const Text('Test Dialog'),
              onPressed: () {
                CustomToast.displaySuccessToast(
                  context,
                  'Test success',
                );
              },
            ),
          );
        },
      ),
    )));
    final button = find.byType(ElevatedButton);
    await tester.tap(button);
    await tester.pump(const Duration(seconds: 2));
    expect('Test success', findsOneWidget); //Cannot find the text
  });
}
`

My Motion toast implementation.
`import 'package:flutter/material.dart';
import 'package:motion_toast/motion_toast.dart';

class CustomToast {
  static void displaySuccessToast(BuildContext context, String mensaje) {
    MotionToast.success(
      title: const Text(
        'Exito',
        style: TextStyle(fontWeight: FontWeight.bold),
      ),
      description: Text(
        mensaje,
        style: const TextStyle(fontSize: 12),
      ),
      dismissable: true,
    ).show(context);
  }
}

Thanks.