Skip to content

Commit

Permalink
test(CodeBlock)
Browse files Browse the repository at this point in the history
  • Loading branch information
topheman committed Apr 24, 2018
1 parent 9a602d7 commit ecd1ace
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ LinkRenderer.defaultProps = {

/** Markdown component */

// note: Markdown component only transfers className as remaining props (not style or others)
const Markdown = ({ repository, source, ...remainingProps }) => (
<ReactMarkdown
source={source}
Expand Down
1 change: 1 addition & 0 deletions src/components/Package/Readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const styles = theme => ({
}
});

// note: Markdown component only transfers className as remaining props (not style or others) - so does Readme
const Readme = ({
classes,
source,
Expand Down
14 changes: 10 additions & 4 deletions src/components/__tests__/CodeBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ describe("/components/CodeBlock", () => {
"Hello world"
);
});
it("should pass value as child", () => {
const { getByText } = render(
<CodeBlock value="some code" language="js" />
);
expect(getByText("some code")).toBeTruthy();
});
it("should set className on <code> element according to props.language", () => {
const { container } = render(<CodeBlock value="" language="js" />);
const [codeElement] = container.getElementsByClassName("language-js");
expect(codeElement).toBeTruthy();
const { getByText } = render(
<CodeBlock value="some code" language="js" />
);
expect(getByText("some code")).toHaveClass("language-js");
});
// @todo test markdown formatting
});
});
23 changes: 23 additions & 0 deletions src/components/__tests__/Markdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import { render } from "../../testUtils";

import Markdown from "../Markdown";

describe("/components/Markdown", () => {
describe("render", () => {
it("should ONLY pass className from remainingProps", () => {
const { container } = render(
<Markdown
className="hello-world"
style={{ color: "red" }}
data-infos="Hello world"
/>
);
expect(container.firstChild).toHaveClass("hello-world");
expect(container.firstChild.style.color).not.toBe("red");
expect(container.firstChild.getAttribute("data-infos")).not.toBe(
"Hello world"
);
});
});
});

0 comments on commit ecd1ace

Please sign in to comment.