Skip to content

Commit

Permalink
adding server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Peleg Rosenthal committed Sep 21, 2016
1 parent 3d6fb22 commit e7bc6a1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/test/HelmetTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,11 @@ describe("Helmet", () => {
`<script ${HELMET_ATTRIBUTE}="true" src="http://localhost/test2.js" type="text/javascript"></script>`
].join("");

const stringifiedNoscriptTags = [
`<noscript ${HELMET_ATTRIBUTE}="true" id="foo"><link rel="stylesheet" type="text/css" href="/style.css" /></noscript>`,
`<noscript ${HELMET_ATTRIBUTE}="true" id="bar"><link rel="stylesheet" type="text/css" href="/style2.css" /></noscript>`
].join("");

const stringifiedStyleTags = [
`<style ${HELMET_ATTRIBUTE}="true" type="text/css">body {background-color: green;}</style>`,
`<style ${HELMET_ATTRIBUTE}="true" type="text/css">p {font-size: 12px;}</style>`
Expand Down Expand Up @@ -1507,6 +1512,47 @@ describe("Helmet", () => {
}</div>`);
});

it("will render noscript tags as React components", () => {
ReactDOM.render(
<Helmet
noscript={[
{id: "foo", innerHTML: '<link rel="stylesheet" type="text/css" href="/style.css" />'},
{id: "bar", innerHTML: '<link rel="stylesheet" type="text/css" href="/style2.css" />'}
]}
/>,
container
);

const head = Helmet.rewind();

expect(head.noscript).to.exist;
expect(head.noscript).to.respondTo("toComponent");

const noscriptComponent = head.noscript.toComponent();

expect(noscriptComponent)
.to.be.an("array")
.that.has.length.of(2);

noscriptComponent.forEach(noscript => {
expect(noscript)
.to.be.an("object")
.that.contains.property("type", "noscript");
});

const markup = ReactServer.renderToStaticMarkup(
<div>
{noscriptComponent}
</div>
);

expect(markup)
.to.be.a("string")
.that.equals(`<div>${
stringifiedNoscriptTags
}</div>`);
});

it("will render style tags as React components", () => {
ReactDOM.render(
<Helmet
Expand Down

0 comments on commit e7bc6a1

Please sign in to comment.