jest snapshot testing: how to ignore part of the snapshot file in jest test results

Now you can also use property matcher for these cases.

By example to be able to use snapshot with these object :

const obj = {
  id: dynamic(),
  foo: 'bar',
  other: 'value',
  val: 1,
};

You can use :

expect(obj).toMatchSnapshot({
  id: expect.any(String),
});

Jest will just check that id is a String and will process the other fields in the snapshot as usual.

Leave a Comment