- Introduction
- Fluent Interface
- Reporters
- Scrubbers
- File Options
- Custom Comparators
- Defaults
- Adding to Existing Options object
There are many things you might want to tweak with Approval Tests. Options is the entry-point for many of the changes.
It is on all verify() methods, as an optional parameter.
Options utilizes a fluent interface, allowing you to chain together commands. Each returned object is a new copy.
new Options().withReporter(new ReportNothing()).withScrubber(new GuidScrubber()).forFile()
.withExtension(".json");Reporters launch diff tools upon failure. Read how to configure them with Options here:
Scrubbers clean output to help remove inconsistent pieces of text, such as dates. Read how to set up Scrubbers here: There are two ways to set a Scrubber.
The Options.forFile() class exists to customise the .approved and .received files in various ways.
If you want to change the file extension of both the approved and received files, use withExtension().
Approvals.verify("text to be verified", new Options().forFile().withExtension(".xyz"));Note: withExtension() returns an Options object, so it's possible to keep appending more with...() calls.
By default Approval Tests will only check if the .approved and .received files are exactly matching.
The only accomodations it makes is for differences in line endings.
If you would like to create a more flexible comparison, you can do it by using the Options.withComparator() function.
The default constructor for Options does:
- no scrubbing
- uses file extension
.txt - uses whatever is currently set as the default reporter.
Each instance of Options is not mutable. Therefore, every call produces a new copy of the Options object. This allows you to modify a specific option from an existing Options object, while retaining all other settings, and not changing the original object.