Created
February 1, 2018 06:48
-
-
Save MaximeHeckel/213c02a56940fc030089471c05d4da48 to your computer and use it in GitHub Desktop.
Medium - React "sub-components" - Article test file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { mount } from 'enzyme'; | |
import Article from '../'; | |
// First we declare some mocks | |
const Content = () => <div>[Mock] Content</div>; | |
const Subtitle = () => <div>[Mock] Subtitle</div>; | |
const Comments = () => <div>[Mock] Comments</div>; | |
const Metadata = () => <div>[Mock] Metadata</div>; | |
const Title = () => <div>[Mock] Title</div>; | |
const Subtitles = () => <div>[Mock] Subtitles</div>; | |
it('Renders with all the sub-components', () => { | |
// Then we try to render the Article component with the desired sub-components | |
const component = mount( | |
<Article> | |
<Article.Title> | |
<Title /> | |
</Article.Title> | |
<Article.Subtitle> | |
<Subtitle /> | |
</Article.Subtitle> | |
<Article.Metadata> | |
<Metadata /> | |
</Article.Metadata> | |
<Article.Content> | |
<Content /> | |
</Article.Content> | |
<Article.Comments> | |
<Comments /> | |
</Article.Comments> | |
</Article> | |
); | |
// Finally we check it matches its snapshot stored in the project | |
expect(component).toMatchSnapshot(); | |
}); | |
it('Renders with only the Content and Comments', () => { | |
// We can iterate the same process again with a different combination of sub-components | |
const component = mount( | |
<Article> | |
<Article.Content> | |
<Content /> | |
</Article.Content> | |
<Article.Comments> | |
<Comments /> | |
</Article.Comments> | |
</Article> | |
); | |
expect(component).toMatchSnapshot(); | |
}); | |
it('Renders with a Title and without a subtitle', () => { | |
const component = mount( | |
<Article> | |
<Article.Title> | |
<Title /> | |
</Article.Title> | |
<Article.Metadata> | |
<Metadata /> | |
</Article.Metadata> | |
<Article.Content> | |
<Content /> | |
</Article.Content> | |
<Article.Comments> | |
<Comments /> | |
</Article.Comments> | |
</Article> | |
); | |
expect(component).toMatchSnapshot(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment