I was trying to write unit tests for some of my LWC components, however the ones that use custom labels throw the following exception
[LWC error]: Invalid operation on Element [object:vm undefined (2)]. Elements created via a template should not be mutated using DOM APIs. Instead of attempting to update this element directly to change the value of attribute "title", you can update the state of the component, and let the engine to rehydrate the element accordingly.
<lightning-button>
From my understanding within Jest, the custom labels don't exist so I need some way to mock them out. From the documentation, it mentions to use a jest-transformer but doesn't show a working example of how to do it.
I've also used the latter example, which does not work as well. I copied the same format to mock out the specific label in my test file and I still received the same exception.
import myImport from '@salesforce/label/c.specialLabel';
jest.mock('@salesforce/label/c.specialLabel', () => {
return { default: "value set in test" };
}, { virtual: true });
What is the proper way to mock out custom labels in LWC for a DX org?