Available Tests

Each modddel's tester has 3 kinds of tests available :

"isValid" tests

The tester has a method named isValid. It checks that the modddel, when instantiated with the given parameters, is valid .

// We test that the Age instantiated with a value of '19' is a ValidAge.
testAge.isValid(const AgeParams(19));

"isSanitized" tests

The tester has a method named isSanitized. It checks that the modddel, when instantiated with the given parameters, holds the sanitizedParams (See the sanitization section).

// We test that the Name is trimmed before being stored inside the modddel.
testAge.isSanitized(
  const NameParams('  Dash '),
  sanitizedParams: const NameParams('Dash'),
);

"isInvalid" tests

For each validationStep, the tester has a matching isInvalid method (Ex : if a validationStep is named "Value", the method will be isInvalidValue).

It tests that the modddel, when instantiated with the given parameters, is an instance of the invalid-step union-case matching the validationStep, and holds the given failures.

For example :

// We test that the Age instantiated with a value of '12' is an InvalidAgeValue,
// and holds the given legalFailure.
testAge.isInvalidValue(
  const AgeParams(12),
  legalFailure: const AgeLegalFailure.minor(),
);

Another example where the validationStep contains the contentValidation :

// We test that the User is an InvalidUserMid, and holds the given contentFailure.
testUser.isInvalidMid(
  UserParams(
    username: Username(value: 'dash'),
    age: Age(5),
  ),
  contentFailure: ContentFailure([
    ModddelInvalidMember(member: Age(5), description: 'age'),
  ]),
);

Note that the order of the ModddelInvalidMembers doesn't matter here (behind the scenes, the unorderedEquals matcher is used for comparing the modddel's contentFailure with the provided one). For more information about ContentFailure and ModddelInvalidMember, read this section.

Like for the Modddel, the dependency parameters are not taken into account for equality in ModddelParams, and are not included in the toString output of the ModddelParams.