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

[Question] Failing tests #34

Open
ehhc opened this issue Jan 30, 2019 · 5 comments
Open

[Question] Failing tests #34

ehhc opened this issue Jan 30, 2019 · 5 comments

Comments

@ehhc
Copy link

ehhc commented Jan 30, 2019

Hey guys,
Thanks for this cool library. I'm using it and i want to write WidgetTests for my app. The following shows a minimal working example of the app. Unfortunately my test is failing and i don't understand why. Can you help me by explaining why? How do i get my test running?

My App:

import 'package:flutter/material.dart';
import 'package:flutter_pagewise/flutter_pagewise.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: PageWiseWidget()
    );
  }
}

class PageWiseWidget extends StatefulWidget{
  @override
  PageWiseWidgetState createState() {
    return PageWiseWidgetState();
  }
}

class PageWiseWidgetState extends State<PageWiseWidget> {
  @override
  Widget build(BuildContext context) {
    return
      Column(
          children: [
            Expanded(
                child: PagewiseListView(
                  pageFuture: BackendService.getPage,
                  pageSize: 10,
                  itemBuilder: (context, entry, _) => Text(entry['name']),
                )
            ),
          ]
      );
  }
}

class BackendService {
  static Future<List> getPage(pageIndex) async {
    List list = List.generate(pageIndex < 6 ? 10 : 5, (index) {
      int dataNumber = index + pageIndex * 10;
      return {
        'name': 'product' + dataNumber.toString(),
      };
    });
    return list;
  }
}

The failing test:


import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:page_wise_test/main.dart';

void main() {
  testWidgets('Elements are shown', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
          return MaterialApp(
            home: Material(
                child: PageWiseWidget()
            ),
          );
        })
    );
    expect(find.text('product3'), findsOneWidget);
  });
}

The error message is:

The following TestFailure object was thrown running a test:
  Expected: exactly one matching node in the widget tree
  Actual: ?:<zero widgets with text "product3" (ignoring offstage widgets)>
   Which: means none were found but one was expected

Do you have any idea why the product is shown in the running app but is not visible during the tests?
Thanks a lot :)

@AbdulRahmanAlHamali
Copy link
Owner

Hmmmm I am not sure. The Pagewise components only load their new components when we scroll down to them. This test could be failing because the "scrolling" is not happening, but I cannot confirm that.

I will try to test it in a couple of days and will get back to you

@AbdulRahmanAlHamali
Copy link
Owner

Hello @ehhc, I apologize but I have not been able to test your issue yet. Were you able to make any progress?

@ehhc
Copy link
Author

ehhc commented Feb 6, 2019

hi @AbdulRahmanAlHamali thanks for your answer. No i wasn't able to make any progress.. The test (as given in the first post) fails and i'm not sure how to work around that.. Nonetheless, i noticed that the problem is not as urgent as i initially thought. I noticed that my main problem was not directly caused by your library but because i'm new to flutter and misunderstood something. Anyway: i think in the long run it would be nice to have some tests for your library as well. Furtunately it aint that pressing anymore :)

@AbdulRahmanAlHamali
Copy link
Owner

Alright great to know you're not blocked by anything!

And I definitely agree, this is on the roadmap, and will let you know once your issue is solved!

@ehhc
Copy link
Author

ehhc commented Feb 6, 2019

Thanks again :)

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

2 participants