Class Expect
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomparator(SnapshotComparator comparator) Apply a custom comparator for this snapshotcomparator(String name) Apply a custom comparator for this snapshotAdd anything you like to the snapshot header.Mask all matches of a regular expression in the serialized snapshot body.static Expectof(SnapshotVerifier snapshotVerifier, Method method) reporters(SnapshotReporter... reporters) Apply a list of custom reporters for this snapshot This will replace the default reporters defined in the configApply a list of custom reporters for this snapshot This will replace the default reporters defined in the configNormally a snapshot can be applied only once to a test method.serializer(SnapshotSerializer serializer) Apply a custom serializer for this snapshotserializer(Class<? extends SnapshotSerializer> serializer) Apply a custom serializer for this snapshot.serializer(String name) Apply a custom serializer for this snapshotvoidtoMatchSnapshot(Object object) Make an assertion on the given input parameters against what already exists
-
Constructor Details
-
Expect
public Expect()
-
-
Method Details
-
of
-
toMatchSnapshot
Make an assertion on the given input parameters against what already existsIf you were previously using varargs and see an error - you can fix the error using "toMatchSnapshotLegacy", however, a better approach is to use the ".scenario()" feature as future versions of this library will most likely remove the legacy implementation completely.
- Parameters:
object- snapshot object
-
mask
Mask all matches of a regular expression in the serialized snapshot body.Masks are applied in registration order, after serialization and before saving or comparing the snapshot. Snapshot names, scenarios and headers are not masked.
The replacement follows
Matcher.replaceAll(String)semantics, including capture-group references. UseMatcher.quoteReplacement(String)for literal replacements containing dollar signs or backslashes.- Parameters:
regex- regular expression to matchreplacement- replacement for each match- Returns:
- this
- Throws:
PatternSyntaxException- if the regular expression is invalidNullPointerException- if regex or replacement is null
-
scenario
Normally a snapshot can be applied only once to a test method.For Parameterized tests where the same method is executed multiple times you can supply the scenario() to overcome this restriction. Ensure each scenario is unique.
- Parameters:
scenario- - unique scenario description- Returns:
- Snapshot
-
serializer
Apply a custom serializer for this snapshot- Parameters:
serializer- your custom serializer- Returns:
- Snapshot
-
serializer
Apply a custom serializer for this snapshot- Parameters:
name- - the {name} attribute serializer.{name} from snapshot.properties- Returns:
- Snapshot
-
comparator
Apply a custom comparator for this snapshot- Parameters:
comparator- your custom comparator- Returns:
- Snapshot
-
comparator
Apply a custom comparator for this snapshot- Parameters:
name- the {name} attribute comparator.{name} from snapshot.properties- Returns:
- Snapshot
-
reporters
Apply a list of custom reporters for this snapshot This will replace the default reporters defined in the config- Parameters:
reporters- your custom reporters- Returns:
- Snapshot
-
reporters
Apply a list of custom reporters for this snapshot This will replace the default reporters defined in the config- Parameters:
name- the {name} attribute reporters.{name} from snapshot.properties- Returns:
- Snapshot
-
serializer
Apply a custom serializer for this snapshot.- Parameters:
serializer- your custom serializer- Returns:
- this
- See Also:
-
header
Add anything you like to the snapshot header.These custom headers can be used in serializers, comparators or reporters to change how they behave.
- Parameters:
key- keyvalue- value- Returns:
- Expect
-