Skip to content

Latest commit

 

History

History
78 lines (52 loc) · 2.88 KB

File metadata and controls

78 lines (52 loc) · 2.88 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 QuietReporter()).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.

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