Skip to content

Commit

Permalink
Implement initial snapshot tests for existing components
Browse files Browse the repository at this point in the history
This commit implements the first snapshot tests for all existing
components. The snapshots approach has been chosen by purpose because
all components are in initial implementation state and actually only
render a React `<Fragment>`.

It also fixes the resulting problems with `propType` violations for the
`Landing` (index/root) page which renders the `Root` component without
passing children. This has been fixed by using a `React.Fragment`.

GH-39
  • Loading branch information
arcticicestudio committed Nov 24, 2018
1 parent dba8c65 commit fe7278e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/
import React from "react";
import React, { Fragment } from "react";

import Root from "containers/core/Root";

Expand All @@ -17,6 +17,10 @@ import Root from "containers/core/Root";
* @author Sven Greb <[email protected]>
* @since 0.1.0
*/
const Landing = () => <Root />;
const Landing = () => (
<Root>
<Fragment />
</Root>
);

export default Landing;
22 changes: 22 additions & 0 deletions test/components/containers/core/Root/Root.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

import React, { Fragment } from "react";
import { render } from "react-testing-library";

import Root from "containers/core/Root";

test("snapshot", () => {
const { container } = render(
<Root>
<Fragment />
</Root>
);
expect(container).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot 1`] = `<div />`;
3 changes: 3 additions & 0 deletions test/pages/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot 1`] = `<div />`;
18 changes: 18 additions & 0 deletions test/pages/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

import React from "react";
import { render } from "react-testing-library";

import Landing from "pages";

test("snapshot", () => {
const { container } = render(<Landing />);
expect(container).toMatchSnapshot();
});

0 comments on commit fe7278e

Please sign in to comment.