Updating Metadata to use react-testing-library

This commit is contained in:
Jeff Avallone 2019-03-24 14:16:07 -04:00
parent a1281543e2
commit 0d512a1a4d
2 changed files with 43 additions and 33 deletions

View File

@ -1,31 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Metadata rendering 1`] = `
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
htmlAttributes={
Object {
"lang": "test-lang",
<DocumentFragment>
<span
data-component="HelmetWrapper"
data-props="{
\\"htmlAttributes\\": {
\\"lang\\": \\"test-lang\\"
}
}
>
}"
>
<title>
Regexper
</title>
</HelmetWrapper>
</span>
</DocumentFragment>
`;
exports[`Metadata rendering with a title and description 1`] = `
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
htmlAttributes={
Object {
"lang": "test-lang",
<DocumentFragment>
<span
data-component="HelmetWrapper"
data-props="{
\\"htmlAttributes\\": {
\\"lang\\": \\"test-lang\\"
}
}
>
}"
>
<title>
Regexper - Testing
</title>
@ -33,5 +34,6 @@ exports[`Metadata rendering with a title and description 1`] = `
content="Test description"
name="description"
/>
</HelmetWrapper>
</span>
</DocumentFragment>
`;

View File

@ -1,5 +1,13 @@
jest.mock('react-helmet', () => {
const helmet = jest.requireActual('react-helmet');
return {
...helmet,
Helmet: require('__mocks__/component-mock').buildMock(helmet.Helmet)
};
});
import React from 'react';
import { shallow } from 'enzyme';
import { render } from 'react-testing-library';
import { Metadata } from 'components/Metadata';
@ -9,19 +17,19 @@ const commonProps = {
describe('Metadata', () => {
test('rendering', () => {
const component = shallow(
const { asFragment } = render(
<Metadata { ...commonProps } />
);
expect(component).toMatchSnapshot();
expect(asFragment()).toMatchSnapshot();
});
test('rendering with a title and description', () => {
const component = shallow(
const { asFragment } = render(
<Metadata
title="Testing"
description="Test description"
{ ...commonProps } />
);
expect(component).toMatchSnapshot();
expect(asFragment()).toMatchSnapshot();
});
});