-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EuiCodeBlock] Cannot be used in Jest Snapshots when language is specified #2242
Comments
Thanks for taking this one @chandlerprall I looked very briefly earlier and found that there are no problems when using |
By design, components which require // attribute map taken from react-dom
const reactAttributeNameMap = {
acceptCharset: 'accept-charset',
className: 'class',
htmlFor: 'for',
httpEquiv: 'http-equiv',
};
function createNodeMock({ type, props }) {
const element = document.createElement(type);
const propNames = Object.keys(props);
propNames.forEach(name => {
const attributeName = reactAttributeNameMap.hasOwnProperty(name) ? reactAttributeNameMap[name] : name;
element.setAttribute(attributeName, props[name]);
});
return element;
}
// ...
renderer.create(
<EuiCodeBlock language="yml">var hello = 'world';</EuiCodeBlock>,
{ createNodeMock }
);
// ... |
The problem is that this requires an internal knowledge of the component in question. I can add a mock of some kind to our shots test which would mean I'd simply know that something in the tree uses a ref.
Is it possible to holistically approach a fix, where I wouldn't need to understand this? |
The |
While I'd prefer to see a mock included as part of Option 1: Directly mock the component that uses a refjest.mock('@elastic/eui/lib/components/code/_code_block', () => ({
EuiCodeBlockImpl: 'code',
propTypes: {}, // Necessary; used by composing components
})); Result
Option 2: Use Storyshots
|
This was likely resolved by replacing highlight.js in #4638 |
This is resolved by the switch to prism.js and the update to how the fallback language is handled. Feel free to re-open if I'm mistaken. |
Jest Snapshot tests that include components that use
EUICodeBlock
fail with the following error:To Reproduce
language="yml"
.The text was updated successfully, but these errors were encountered: