Closed jeffhube closed 1 year ago
Thanks for opening the issue. This is currently by design.
However, there is a case to be made that we should not throw an error in dev mode where the same error would not be thrown in prod mode: https://github.com/salesforce/lwc/issues/3245
As a quick fix, we can disable this check in Jest.
Fixed by https://github.com/salesforce/lwc/issues/3245. Thanks for reporting!
Description
Jest, in certain cases, may attempt to print out a lightning component element. In doing so, it will attempt to access the
tagName
, which throws an error:This error comes from https://github.com/salesforce/lwc/blob/61a89c3f41a211bcc27b4878f2f2d83b279e1ea6/packages/%40lwc/engine-core/src/framework/restrictions.ts#L272
I encountered this when attempting to assert that a method was not called, when it was in fact called, and a lightning component element was passed as an argument. Jest attempts to print out the arguments to the method that was not expected to be called. If one of those arguments is lightning component element, it attempts to access
tagName
and throws an error.For reference, this is what Jest's output normally looks like, when the argument is
"a string"
rather than a lightning component element.Steps to Reproduce
Expected Results
The unit test fails with an error about how
foo
was called 1 time but was expected to be called 0 times.Actual Results
The unit test fails with an error about accessing
tagName
.Version
Additional context/Screenshots
Here are some details about how I encountered this. I have a utility component that contains a method for displaying an error as a toast.
When a component wants to display an error toast, it calls
errorToast
, passing itself and the error.In a test, I want to confirm that the errorToast function was not called.