Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 3.24 KB

File metadata and controls

85 lines (57 loc) · 3.24 KB

Options

Contents

Introduction

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.

Fluent Interface

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");

snippet source | anchor

Reporters

Reporters launch diff tools upon failure. Read how to configure them with Options here:

Scrubbers

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.

File Options

The Options.forFile() class exists to customise the .approved and .received files in various ways.

File Extensions

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"));

snippet source | anchor

Note: withExtension() returns an Options object, so it's possible to keep appending more with...() calls.

Custom Comparators

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.

Defaults

The default constructor for Options does:

  • no scrubbing
  • uses file extension .txt
  • uses whatever is currently set as the default reporter.

Adding to Existing Options object

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.


Back to User Guide