java-snapshot-testing icon indicating copy to clipboard operation
java-snapshot-testing copied to clipboard

Add REGEX masking ability

Open jackmatt2 opened this issue 2 years ago • 0 comments

In order to help make tests more deterministic - add REGEX masking capability

ie. to mask dates in your output, you might supply the following

expect.mask("\\d{2}-\\d{2}-\d{4}", "**-**-****").toMatchSnapshot(obj)

You can supply multiple masks

expect
  .mask("\\d{2}-\\d{2}-\d{4}", "**-**-****") // mask dates
  .mask("(?m)^$", "** empty line ***\n") // mask empty lines
  .toMatchSnapshot(obj)

Masks can be used to make invisible characters more obvious

expect
  .mask("(?m)^\t+$", "TABS_ONLY") // mask invisible character more obvious
  .toMatchSnapshot(obj)

jackmatt2 avatar Jan 24 '23 08:01 jackmatt2