SandroMaglione / fpdart

Functional programming in Dart and Flutter. All the main functional programming types and patterns fully documented, tested, and with examples.
https://pub.dev/packages/fpdart
MIT License
542 stars 45 forks source link

Test Helpers #70

Open ryanhanks opened 1 year ago

ryanhanks commented 1 year ago

Any plans to provide test helpers? Something like https://pub.dev/packages/dartz_test maybe?

SandroMaglione commented 1 year ago

Hi @ryanhanks

Thanks for the suggestion! Indeed, fpdart internally already defines some util methods for testing.

This is definitely something planned for the near future. Meanwhile, if anyone has any suggestions feel free to leave a comment here 👍

zellidev0 commented 7 months ago

@SandroMaglione

We use those in our project. Would you be interested in me adding it as a PR including documentation?

Matcher isLeft<T>(
  final Matcher? leftMatcher,
) => ...

Matcher isRight<T>(
  final Matcher? rightMatcher,
)

Matcher isSome<T>(
  final Matcher? someMatcher,
) => ...

Matcher isNone => ...

We use them like so:

expect(
     inAppPurchasePayment.subscriptionServiceApiBuilder,
     isNone,
);
expect(
    inAppPurchasePayment.subscriptionServiceApiBuilder,
    isSome<SubscriptionV2ControllerApiBuilder>(),
);
expect(
    inAppPurchasePayment.subscriptionServiceApiBuilder,
    isSome<SubscriptionV2ControllerApiBuilder>(
        predicate(
         (final SubscriptionV2ControllerApiBuilder builder) => builder ==  exampleBuilder,
        ),
    ),
);
SandroMaglione commented 7 months ago

@zellidev0 I already set up a fpdart_test package folder. The plan would be to add a separate testing library for fpdart.

I think the methods you propose may come handy once fpdart_test will be ongoing

SAGARSURI commented 6 months ago

Hey @SandroMaglione any update on the test package? Specially looking for unwrapping data from TaskEither to expect. Currently there is not clean way of doing it.

SandroMaglione commented 5 months ago

Hey @SAGARSURI

A possible fpdart v2 is currently work in progress (#147). This will bring many changes, so I think it's better to wait for v2 before starting the work on support tooling (tests, linting)