fix(mock-doc): make MockAttributeMap iterable #2788
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR Proposed changes:
[Symbol.iterator]
inMockAttributeMap
to make it iterableget [Symbol.toStringTag]
inMockAttributeMap
isNaN
in attribute proxyWhen writing E2E tests I ran into different
PrettyFormatPluginError
errors, when Jest would try to pretty-format anE2EElement
while iterating over its attributes:or
This error might only happen in my case because I'm using
jest@26
and I think Stencil still defaults tojest@25
, but doesn't complain if a higher major version is used cause it's likely compatible.Anyway, after debugging this for half a day, I figured out that
pretty-format
fails to print the attributes becauseMockAttributeMap
is not really iterable but it tries to iterate it (passed intoArray.from
, see facebook/jest/pretty-format/src/plugins/DOMElement.ts#L87 and facebook/jest/pretty-format/src/plugins/DOMElement.ts#L87), and ends up being an Array ofundefined
s (not sure why).The solution is to add an implementation of
[Symbol.iterator]
. Another symbol that pretty-format tries to access isSymbol.toStringTag
so I've also implemented that.Also, the attribute proxy uses
isNaN
which breaks when called on a symbol:thus I've added a check for that.