twilio-labs/paste

Not able to write snapshots based tests due to dynamic id generation

pranshuchittora opened this issue · 1 comments

Description

Hey Folks,
I am trying to write some snapshots based UTs using react testing library. But unable to due to dynamic id generation

Screenshot 2022-11-23 at 17 46 50

I tried wrapping the component with a theme provider, but still the its are dynamic. Let me know if I am doing anything incorrectly or there's any workaround for the same

Link to Reproduction

NA

Steps to reproduce

No response

Paste Core Version

10.20.0

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

Hi @pranshuchittora

This functionality is working as intended for accessibility reasons.

I go into some detail about the why in this discussion post #1940

TL;DR

Don’t write snapshot tests. A better more reliable and intentional approach to testing is to expect specific functionality, or attributes to be found in the DOM. A failed snapshot test doesn’t tell you if the functionality or expected behavior failed, just that some thing changed.