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,30 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Metadata rendering 1`] = ` exports[`Metadata rendering 1`] = `
<HelmetWrapper <DocumentFragment>
defer={true} <span
encodeSpecialCharacters={true} data-component="HelmetWrapper"
htmlAttributes={ data-props="{
Object { \\"htmlAttributes\\": {
"lang": "test-lang", \\"lang\\": \\"test-lang\\"
}
} }
}"
> >
<title> <title>
Regexper Regexper
</title> </title>
</HelmetWrapper> </span>
</DocumentFragment>
`; `;
exports[`Metadata rendering with a title and description 1`] = ` exports[`Metadata rendering with a title and description 1`] = `
<HelmetWrapper <DocumentFragment>
defer={true} <span
encodeSpecialCharacters={true} data-component="HelmetWrapper"
htmlAttributes={ data-props="{
Object { \\"htmlAttributes\\": {
"lang": "test-lang", \\"lang\\": \\"test-lang\\"
}
} }
}"
> >
<title> <title>
Regexper - Testing Regexper - Testing
@ -33,5 +34,6 @@ exports[`Metadata rendering with a title and description 1`] = `
content="Test description" content="Test description"
name="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 React from 'react';
import { shallow } from 'enzyme'; import { render } from 'react-testing-library';
import { Metadata } from 'components/Metadata'; import { Metadata } from 'components/Metadata';
@ -9,19 +17,19 @@ const commonProps = {
describe('Metadata', () => { describe('Metadata', () => {
test('rendering', () => { test('rendering', () => {
const component = shallow( const { asFragment } = render(
<Metadata { ...commonProps } /> <Metadata { ...commonProps } />
); );
expect(component).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
}); });
test('rendering with a title and description', () => { test('rendering with a title and description', () => {
const component = shallow( const { asFragment } = render(
<Metadata <Metadata
title="Testing" title="Testing"
description="Test description" description="Test description"
{ ...commonProps } /> { ...commonProps } />
); );
expect(component).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
}); });
}); });