Prompt
What should I use to avoid noisy diffs from animations and timestamps?
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
Use a snapshot serializer or test-specific normalization to strip out unstable fields before comparing snapshots.
Common approaches:
- Jest snapshot serializers for things like animation state, IDs, timestamps, dates, random values
- Custom matchers / preprocessing to remove or replace dynamic values
- Mocking time with fake timers or fixed dates when timestamps are involved
Typical examples:
- Replace timestamps with a constant value
- Ignore animation-related props or styles
- Normalize generated IDs
If you’re using Jest, the most common answer is:
expect.addSnapshotSerializer({
test: val => typeof val === 'object',
print: (val, serialize) => {
// return a cleaned version of val here
},
});
Or simpler, mock the unstable parts:
jest.useFakeTimers();
jest.setSystemTime(new Date('2024-01-01T00:00:00Z'));
If you want, I can show the best practice for your specific stack, like Jest, React Testing Library, or Storybook.