Skip to content

Commit

Permalink
handle null values for tags (and fix eslinting error) (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewheck authored and cwelch5 committed Nov 6, 2016
1 parent aff3858 commit f0b971c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Helmet.js
Expand Up @@ -111,7 +111,7 @@ const getTagsFromPropsList = (tagName, primaryAttributes, propsList) => {
}
}

if (!primaryAttributeKey) {
if (!primaryAttributeKey || !tag[primaryAttributeKey]) {
return false;
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/HelmetTest.js
Expand Up @@ -997,6 +997,33 @@ describe("Helmet", () => {
expect(secondTag.getAttribute("href")).to.equal("http://localhost/helmet/innercomponent");
expect(secondTag.outerHTML).to.equal(`<link rel="canonical" href="http://localhost/helmet/innercomponent" ${HELMET_ATTRIBUTE}="true">`);
});

it("will remove tags with null values", () => {
ReactDOM.render(
<Helmet
link={[
{"rel": "icon", "sizes": "192x192", "href": null},
{"rel": "canonical", "href": "http://localhost/helmet/component"}
]}
/>,
container
);

const tagNodes = headElement.querySelectorAll(`link[${HELMET_ATTRIBUTE}]`);
const existingTags = Array.prototype.slice.call(tagNodes);
const firstTag = existingTags[0];

expect(existingTags).to.not.equal(undefined);
expect(existingTags.length).to.be.equal(1);

expect(existingTags)
.to.have.deep.property("[0]")
.that.is.an.instanceof(Element);
expect(firstTag).to.have.property("getAttribute");
expect(firstTag.getAttribute("rel")).to.equal("canonical");
expect(firstTag.getAttribute("href")).to.equal("http://localhost/helmet/component");
expect(firstTag.outerHTML).to.equal(`<link rel="canonical" href="http://localhost/helmet/component" ${HELMET_ATTRIBUTE}="true">`);
});
});

describe("script tags", () => {
Expand Down

0 comments on commit f0b971c

Please sign in to comment.