7

Using TDD I'd like to write some new tests that create data in slightly different ways, and verify that that test data gets sanitized down to the same data as a previous test.

So after writing Test 1 and generating a snapshot, Test 2/3/4 should generate the same snapshot as Test 1.

How can I make that happen? Jest appears to prepend the test name to custom snapshot names so I can't use .match(test1name).

(Using all-new identical snapshots for each test bloats the snapshots file and seems far from ideal.)

Freewalker
  • 6,329
  • 4
  • 51
  • 70

1 Answers1

1

You could do something like:

const r1 = fn1()

expect(r1).toMatchSnapshot()

const r2 = fn1()

expect(r2).toEqual(r1)

Tom
  • 4,666
  • 2
  • 29
  • 48