Skip to content

Conversation

@LukGaming
Copy link
Contributor

@LukGaming LukGaming commented Apr 21, 2023

Add this to the end of the File basic_assertions, then we have VerifyAllAssertions for lists
and we can have
ShouldAllSatisfyExtension of lists

extension VerifyAllAssertions<T> on T? {
  // Asserts that a Each item of the list is an instance of [E].
  /// [E] - Expected type.
  void shouldAllBeInstanceOf<E>() {
    (this as List).forEach((element) {
      expect(element, isA<E>());
    });
  }
}
// Usage
 test(
    "Verify That getServices() return a List of Services",
    () => {servicesList.shouldAllBeInstanceOf<Service>()},
  );
//Given an List, check multiples assertions in a list
extension ShouldAllSatisfyExtension<T> on List<T> {
  void shouldAllSatisfy(void Function(T) assertion) {
    for (final item in this) {
      assertion(item);
    }
  }
}
// Usage
  test(
    "Verify That All Service Fields Are not Null",
    () => {
      servicesList.shouldAllSatisfy((service) {
        service.serviceDone.shouldNotBeNull();
        service.serviceName.shouldNotBeNull();
        service.serviceDoneDay.shouldNotBeNull();
      })
    },
  );

@klisiewicz klisiewicz self-requested a review May 7, 2024 22:06
@klisiewicz klisiewicz self-assigned this Dec 29, 2024
@klisiewicz klisiewicz added the enhancement New feature or request label Dec 29, 2024
@klisiewicz klisiewicz marked this pull request as draft December 29, 2024 22:08
@klisiewicz
Copy link
Owner

klisiewicz commented Dec 31, 2024

Thank you for your input @LukGaming. The 0.5.0 release is going to contain methods that meet your needs:

test(
    "Verify That getServices() return a List of Services",
    () {
        servicesList.shouldAllBeInstanceOf<Service>();
    },
);
test(
    "Verify That All Service Fields Are not Null",
    () => {
      servicesList.shouldContainAllThat((service) {
        return service.serviceDone != null &&
               service.serviceName != null &&
               service.serviceDoneDay != null;
      });
    },
);

@klisiewicz klisiewicz marked this pull request as ready for review January 1, 2025 10:31
@klisiewicz klisiewicz merged commit a8f12fe into master Jan 1, 2025
1 check passed
@klisiewicz klisiewicz deleted the release-0.5.0 branch January 1, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants