Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DiegoVega19 opened this issue Dec 1, 2022 · 0 comments

Comments

@DiegoVega19
Copy link

DiegoVega19 commented Dec 1, 2022

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.

@DiegoVega19 DiegoVega19 changed the title How can I test the title / description that is displayed in the motion toast in a testing widget How can I test the title / description that is displayed in the motion toast in a Widget testing Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant