elementary_test 1.1.0 copy "elementary_test: ^1.1.0" to clipboard
elementary_test: ^1.1.0 copied to clipboard

outdated

A testing library which makes it easy to test elementary used apps. Built to be used with the elementary architecture package.

Elementary-test #

Elementary Logo

Pub Version Pub Likes Pub popularity Flutter Platform

Description #

A handy testing library for the apps built with Elementary. This one’s helpful when used with the Elementary architecture package.

Overview #

This library offers some handy tools to test WidgetModel from the Elementary package.

testWidgetModel method #

The main testing tool is the testWidgetModel function that executes a test. The parameters it requires are the name of a test, the function preparing WidgetModel for testing, and the function of the test itself.

testFunction #

This is a function of a test itself. When passed the WidgetModel, this function describes its behavior and verifies the result. The function also uses a tester to manipulate the phases of a WidgetModel life cycle, and the BuildContext mock.

How to use #

void main() {
  late TestPageModelMock model;
  late ThemeWrapperMock theme;
  late TextThemeMock textTheme;

  TestPageWidgetModel setUpWm() {
    textTheme = TextThemeMock();
    when(() => textTheme.headline4).thenReturn(null);
    theme = ThemeWrapperMock();
    when(() => theme.getTextTheme(any())).thenReturn(textTheme);
    model = TestPageModelMock();
    when(() => model.value).thenReturn(0);
    when(() => model.increment()).thenAnswer((invocation) => Future.value(1));

    return TestPageWidgetModel(model, theme);
  }

  testWidgetModel<TestPageWidgetModel, TestPageWidget>(
    'counterStyle should be headline4',
    setUpWm,
        (wm, tester, context) {
      final style = TextStyleMock();
      when(() => textTheme.headline4).thenReturn(style);

      tester.init();

      expect(wm.counterStyle, style);
    },
  );
  
  testWidgetModel<TestPageWidgetModel, TestPageWidget>(
    'when call increment and before get answer valueState should be loading',
    setUpWm,
        (wm, tester, context) async {
      tester.init();

      when(() => model.increment()).thenAnswer(
            (invocation) => Future.delayed(
          const Duration(milliseconds: 30),
              () => 1,
        ),
      );

      unawaited(wm.increment());

      await Future<void>.delayed(
        const Duration(milliseconds: 10),
      );

      final value = wm.valueState.value;

      expect(value, isNotNull);
      expect(value!.isLoading, isTrue);
    },
  );
}

Our main sponsor is Surf.

Surf

Maintainer #

Mikhail Zotyev

25
likes
0
pub points
72%
popularity

Publisher

verified publisherelementaryteam.dev

A testing library which makes it easy to test elementary used apps. Built to be used with the elementary architecture package.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

elementary, flutter, flutter_test, meta, mocktail

More

Packages that depend on elementary_test