Skip to content

Commit

Permalink
[fix] rewind fallback for htmlAttributes (nfl#191)
Browse files Browse the repository at this point in the history
* [fix] htmlAttributes fallback value [] changed to {}
[update] tests to verify fallback values

* Combined with unit test that already existed for rewind defaults.
  • Loading branch information
cwelch5 authored Nov 16, 2016
1 parent 5df0bb2 commit 0d2da9a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Helmet.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const Helmet = (Component) => {
if (!mappedState) {
// provide fallback if mappedState is undefined
mappedState = mapStateOnServer({
htmlAttributes: [],
htmlAttributes: {},
title: "",
baseTag: [],
metaTags: [],
Expand Down
62 changes: 59 additions & 3 deletions src/test/HelmetTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1932,13 +1932,69 @@ describe("Helmet", () => {

const head = Helmet.rewind();

expect(head).is.not.an("undefined");
expect(head).to.exist;
expect(head.base).to.exist;
expect(head.htmlAttributes).to.exist;
expect(head.htmlAttributes).to.respondTo("toString");
expect(head.htmlAttributes.toString()).to.equal("");
expect(head.htmlAttributes).to.respondTo("toComponent");
expect(head.htmlAttributes.toComponent()).to.be.an("object")
.that.is.empty;

expect(head.title).to.exist;
expect(head.title).to.respondTo("toString");
expect(head.title.toString()).to.equal(`<title ${HELMET_ATTRIBUTE}="true"></title>`);
expect(head.title).to.respondTo("toComponent");

const markup = ReactServer.renderToStaticMarkup(
<div>
{head.title.toComponent()}
</div>
);

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

expect(head.base).to.exist;
expect(head.base).to.respondTo("toString");
expect(head.base.toString()).to.equal("");
expect(head.base).to.respondTo("toComponent");
expect(head.base.toComponent()).to.be.an("array")
.that.is.empty;

expect(head.meta).to.exist;
expect(head.meta).to.respondTo("toString");
expect(head.meta.toString()).to.equal("");
expect(head.meta).to.respondTo("toComponent");
expect(head.meta.toComponent()).to.be.an("array")
.that.is.empty;

expect(head.link).to.exist;
expect(head.link).to.respondTo("toString");
expect(head.link.toString()).to.equal("");
expect(head.link).to.respondTo("toComponent");
expect(head.link.toComponent()).to.be.an("array")
.that.is.empty;

expect(head.script).to.exist;
expect(head.script).to.respondTo("toString");
expect(head.script.toString()).to.equal("");
expect(head.script).to.respondTo("toComponent");
expect(head.script.toComponent()).to.be.an("array")
.that.is.empty;

expect(head.noscript).to.exist;
expect(head.noscript).to.respondTo("toString");
expect(head.noscript.toString()).to.equal("");
expect(head.noscript).to.respondTo("toComponent");
expect(head.noscript.toComponent()).to.be.an("array")
.that.is.empty;

expect(head.style).to.exist;
expect(head.style).to.respondTo("toString");
expect(head.style.toString()).to.equal("");
expect(head.style).to.respondTo("toComponent");
expect(head.style.toComponent()).to.be.an("array")
.that.is.empty;
});

it("does not render undefined attribute values", () => {
Expand Down

0 comments on commit 0d2da9a

Please sign in to comment.