Skip to content

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

Description

@DiegoVega19

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions