Modddels
HomeGithubPub.dev
v0.2
v0.2
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  • "isValid" tests
  • "isSanitized" tests
  • "isInvalid" tests
  1. Unit-Testing Of Modddels

Available Tests

PreviousUnit-Testing OverviewNextCustomizing 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 .

// 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.

(See the sanitization section)