-
Notifications
You must be signed in to change notification settings - Fork 54
add function to detect and render helmet for use in snapshots #2104
Conversation
5949d78
to
d46ae43
Compare
0a04b57
to
140b90c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some simple snapshot tests would be nice IMO as its more complicated
export const shouldMatchSnapshot = (title, component) => { | ||
it(title, () => { | ||
it(title, async () => { | ||
// select the first child to remove the pointless wrapping div from snapshots |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens now :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you worried about the async it
callback? It won't affect the current test helper API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soz i meant select the first child to remove the pointless wrapping div from snapshots
happens now. We no longer remove the pointless wrapping div
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still do when rendering components without helmet. I'll change the comments and var names.
src="test.js" | ||
/> | ||
</head> | ||
<body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any easy way to remove the body when not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into it. Was worried about adding more complexity to an already complex looking function for not much value but it should be straightforward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing the body but that stopped other tests from rendering things in the body. I guess it breaks the renderer because it can't find the body element's div to put stuff in. I also tried this with removing just the div and it had the same effect :(
Jenkins is failing because this updates |
…e-lock.json not sure why this was different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soz for my confusion, looks great :)
Overall change: Adds functionality to
shouldMatchSnapshot
to include html and head tags ifreact-helmet
was used inside of component. This enables us to see things like meta tags and scripts in snapshots.Code changes:
renderWithHelmet
that is a wrapper around the@testing-library/react
render
method.An example using the Chartbeat component in Simorgh
would then render