When using Jest with JSDOM to test HTML elements, it's common to try to use or access the data-attribute. The problem is that it doesn't work.
The solution is quite simple: getAttribute
/ setAttribute
.
element.setAttribute('data-food', 'taco');
element.getAttribute('data-food');
// returns 'taco'
Top comments (0)