react-document-meta
Advanced tools
Comparing version 2.0.0-rc1 to 2.0.0-rc2
@@ -9,6 +9,8 @@ 'use strict'; | ||
var _reactAddons = require('react/addons'); | ||
var _react = require('react'); | ||
var _reactAddons2 = _interopRequireDefault(_reactAddons); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactDomServer = require('react-dom/server'); | ||
var _ = require('../'); | ||
@@ -25,3 +27,3 @@ | ||
it('clears the mounted instances', function () { | ||
_reactAddons2['default'].renderToStaticMarkup(_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' })))); | ||
(0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' })))); | ||
_assert2['default'].deepEqual(_2['default'].peek(), { title: 'c' }); | ||
@@ -34,3 +36,3 @@ _2['default'].rewind(); | ||
var title = 'cheese'; | ||
_reactAddons2['default'].renderToStaticMarkup(_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: title })))); | ||
(0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: title })))); | ||
_assert2['default'].deepEqual(_2['default'].rewind(), { title: title }); | ||
@@ -40,3 +42,3 @@ }); | ||
it('returns undefined if no mounted instances exist', function () { | ||
_reactAddons2['default'].renderToStaticMarkup(_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' })))); | ||
(0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' })))); | ||
_2['default'].rewind(); | ||
@@ -49,3 +51,3 @@ _assert2['default'].strictEqual(_2['default'].peek(), undefined); | ||
it('returns an empty array if no meta data has been mounted', function () { | ||
_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' }))); | ||
_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' }))); | ||
@@ -58,3 +60,3 @@ var rendered = _2['default'].renderAsReact(); | ||
it('returns the latest document meta as an array of React components', function () { | ||
_reactAddons2['default'].renderToStaticMarkup(_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' })))); | ||
(0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' })))); | ||
@@ -65,3 +67,3 @@ var rendered = _2['default'].renderAsReact(); | ||
_assert2['default'].strictEqual(rendered[0].type, 'title'); | ||
_assert2['default'].strictEqual(rendered[0]._store.props.children, 'c'); | ||
_assert2['default'].strictEqual(rendered[0].props.children, 'c'); | ||
}); | ||
@@ -72,3 +74,3 @@ }); | ||
it('returns an empty string if no meta data has been mounted', function () { | ||
_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' }))); | ||
_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' }))); | ||
_assert2['default'].strictEqual(_2['default'].renderAsHTML(), ''); | ||
@@ -78,3 +80,3 @@ }); | ||
it('returns the latest document meta as HTML', function () { | ||
_reactAddons2['default'].renderToStaticMarkup(_reactAddons2['default'].createElement(_2['default'], { title: 'a' }, _reactAddons2['default'].createElement(_2['default'], { title: 'b' }, _reactAddons2['default'].createElement(_2['default'], { title: 'c' })))); | ||
(0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement(_2['default'], { title: 'a' }, _react2['default'].createElement(_2['default'], { title: 'b' }, _react2['default'].createElement(_2['default'], { title: 'c' })))); | ||
_assert2['default'].strictEqual(_2['default'].renderAsHTML(), '<title>c</title>'); | ||
@@ -81,0 +83,0 @@ }); |
@@ -9,6 +9,10 @@ 'use strict'; | ||
var _reactAddons = require('react/addons'); | ||
var _react = require('react'); | ||
var _reactAddons2 = _interopRequireDefault(_reactAddons); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactAddonsTestUtils = require('react-addons-test-utils'); | ||
var _reactAddonsTestUtils2 = _interopRequireDefault(_reactAddonsTestUtils); | ||
var _ = require('../'); | ||
@@ -24,5 +28,5 @@ | ||
describe('React Document Meta', function () { | ||
describe('DocumentMeta - DOM basic', function () { | ||
var docMeta = { | ||
var DOC_META = { | ||
title: 'This is a document title', | ||
@@ -47,24 +51,24 @@ description: 'This meta value is describing the page we are looking at', | ||
(0, _utils.removeDocumentMeta)(); | ||
_reactAddons2['default'].addons.TestUtils.renderIntoDocument(_reactAddons2['default'].createElement(_2['default'], docMeta)); | ||
_reactAddonsTestUtils2['default'].renderIntoDocument(_react2['default'].createElement(_2['default'], DOC_META)); | ||
}); | ||
it('should render document.title / <title> according to the title-attr', function () { | ||
_assert2['default'].strictEqual(document.title, docMeta.title); | ||
_assert2['default'].strictEqual(document.title, DOC_META.title); | ||
}); | ||
it('should render <meta name="description" content="..."> according to the description-attr', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=description]', 'content'), docMeta.description); | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=description]', 'content'), DOC_META.description); | ||
}); | ||
it('should render <link rel="canonical" href="..." according to the canonical-attr', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('link[rel=canonical]', 'href'), docMeta.canonical); | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('link[rel=canonical]', 'href'), DOC_META.canonical); | ||
}); | ||
it('should render simple meta tags, eg. <meta charset="...">', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[charset]', 'charset'), docMeta.meta.charset); | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[charset]', 'charset'), DOC_META.meta.charset); | ||
}); | ||
it('should render normal meta tags, eg. <meta name="..." content="...">', function () { | ||
Object.keys(docMeta.meta.name).reduce(function (name) { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=' + name + ']', 'content'), docMeta.meta.name[name], '<meta name="' + name + '" ... /> has not been rendered correctly'); | ||
Object.keys(DOC_META.meta.name).reduce(function (name) { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=' + name + ']', 'content'), DOC_META.meta.name[name], '<meta name="' + name + '" ... /> has not been rendered correctly'); | ||
}); | ||
@@ -74,4 +78,4 @@ }); | ||
it('should render normal link tags, eg. <link rel="..." href="...">', function () { | ||
Object.keys(docMeta.link.rel).reduce(function (rel) { | ||
var values = Array.isArray(docMeta.link.rel[rel]) ? docMeta.link.rel[rel] : [docMeta.link.rel[rel]]; | ||
Object.keys(DOC_META.link.rel).reduce(function (rel) { | ||
var values = Array.isArray(DOC_META.link.rel[rel]) ? DOC_META.link.rel[rel] : [DOC_META.link.rel[rel]]; | ||
var elements = (0, _testUtils.getElements)('link[rel=' + rel + ']'); | ||
@@ -81,5 +85,4 @@ elements.forEach(function (element, idx) { | ||
}); | ||
// assert.strictEqual( getAttr(`link[rel=${ rel }]`, 'content'), docMeta.link.rel[rel], `<link rel="${ rel }" ... /> has not been rendered correctly` ); | ||
}); | ||
}); | ||
}); |
@@ -1,1 +0,110 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _assert = require('assert'); | ||
var _assert2 = _interopRequireDefault(_assert); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactAddonsTestUtils = require('react-addons-test-utils'); | ||
var _reactAddonsTestUtils2 = _interopRequireDefault(_reactAddonsTestUtils); | ||
var _ = require('../'); | ||
var _2 = _interopRequireDefault(_); | ||
var _utils = require('../utils'); | ||
var _testUtils = require('./test-utils'); | ||
var document = global.document; | ||
describe('DocumentMeta - DOM nested', function () { | ||
var DOC_META = { | ||
title: 'This is a document title', | ||
description: 'This meta value is describing the page we are looking at', | ||
canonical: 'http://domain.tld/path/to/page', | ||
meta: { | ||
charset: 'utf-8', | ||
name: { | ||
keywords: 'react,document,meta,tags' | ||
} | ||
}, | ||
link: { | ||
rel: { | ||
stylesheet: ['http://domain.tld/css/vendor.css', 'http://domain.tld/css/styles.css'] | ||
} | ||
} | ||
}; | ||
var DOC_META_NESTED = { | ||
title: 'This is another document title', | ||
description: null, | ||
canonical: 'http://domain.tld/path/to/other', | ||
meta: { | ||
name: { | ||
keywords: 'react,document,meta,tags,nesting' | ||
} | ||
}, | ||
link: { | ||
rel: {} | ||
} | ||
}; | ||
beforeEach(function () { | ||
_2['default'].canUseDOM = true; | ||
(0, _utils.removeDocumentMeta)(); | ||
_reactAddonsTestUtils2['default'].renderIntoDocument(_react2['default'].createElement( | ||
'div', | ||
null, | ||
_react2['default'].createElement(_2['default'], DOC_META), | ||
_react2['default'].createElement( | ||
'div', | ||
null, | ||
_react2['default'].createElement(_2['default'], _extends({}, DOC_META_NESTED, { extend: true })) | ||
) | ||
)); | ||
}); | ||
it('should render document.title / <title> according to the title-attr', function () { | ||
_assert2['default'].strictEqual(document.title, DOC_META_NESTED.title); | ||
}); | ||
it('should render <meta name="description" content="..."> according to the description-attr', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=description]', 'content'), DOC_META_NESTED.description); | ||
}); | ||
it('should render <link rel="canonical" href="..." according to the canonical-attr', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('link[rel=canonical]', 'href'), DOC_META_NESTED.canonical); | ||
}); | ||
it('should render simple meta tags, eg. <meta charset="...">', function () { | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[charset]', 'charset'), DOC_META.meta.charset); | ||
}); | ||
it('should render normal meta tags, eg. <meta name="..." content="...">', function () { | ||
Object.keys(DOC_META.meta.name).reduce(function (name) { | ||
var value = DOC_META_NESTED.meta.name.hasOwnProperty(name) ? DOC_META_NESTED.meta.name[name] : DOC_META.meta.name[name]; | ||
_assert2['default'].strictEqual((0, _testUtils.getAttr)('meta[name=' + name + ']', 'content'), value, '<meta name="' + name + '" ... /> has not been rendered correctly'); | ||
}); | ||
}); | ||
it('should render normal link tags, eg. <link rel="..." href="...">', function () { | ||
Object.keys(DOC_META.link.rel).reduce(function (rel) { | ||
var value = DOC_META_NESTED.link.rel.hasOwnProperty(rel) ? DOC_META_NESTED.link.rel[rel] : DOC_META.link.rel[rel]; | ||
var values = Array.isArray(value) ? value : [value]; | ||
var elements = (0, _testUtils.getElements)('link[rel=' + rel + ']'); | ||
elements.forEach(function (element, idx) { | ||
_assert2['default'].strictEqual(element.getAttribute('content'), values[idx], '<link rel="' + rel + '" ... /> has not been rendered correctly'); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ 'use strict'; | ||
return element.getAttribute(attr); | ||
return element && element.getAttribute(attr) || null; | ||
} | ||
@@ -18,0 +18,0 @@ |
@@ -19,4 +19,6 @@ 'use strict'; | ||
var _reactLibExecutionEnvironment = require('react/lib/ExecutionEnvironment'); | ||
var _reactDomServer = require('react-dom/server'); | ||
var _exenv = require('exenv'); | ||
var _reactSideEffect = require('react-side-effect'); | ||
@@ -36,6 +38,6 @@ | ||
if (_props.description) { | ||
if (_props.hasOwnProperty('description')) { | ||
(0, _utils.defaults)(_props, { meta: { name: { description: _props.description } } }); | ||
} | ||
if (_props.canonical) { | ||
if (_props.hasOwnProperty('canonical')) { | ||
(0, _utils.defaults)(_props, { link: { rel: { canonical: _props.canonical } } }); | ||
@@ -64,3 +66,3 @@ } | ||
function handleStateChangeOnClient(props) { | ||
if (_reactLibExecutionEnvironment.canUseDOM) { | ||
if (_exenv.canUseDOM) { | ||
document.title = props.title || ''; | ||
@@ -84,6 +86,6 @@ insertDocumentMeta(props); | ||
} | ||
if (p.description && !group['og:description']) { | ||
if (p.hasOwnProperty('description') && !group['og:description']) { | ||
group['og:description'] = p.description; | ||
} | ||
if (p.canonical && !group['og:url']) { | ||
if (p.hasOwnProperty('canonical') && !group['og:url']) { | ||
group['og:url'] = p.canonical; | ||
@@ -113,2 +115,5 @@ } | ||
if (value === null) { | ||
return; | ||
} | ||
tags.push((_tags$push2 = { | ||
@@ -196,3 +201,3 @@ tagName: tagName | ||
return _react2['default'].renderToStaticMarkup(_react2['default'].createElement( | ||
return (0, _reactDomServer.renderToStaticMarkup)(_react2['default'].createElement( | ||
'div', | ||
@@ -211,3 +216,3 @@ null, | ||
canonical: _react2['default'].PropTypes.string, | ||
meta: _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.string)])), | ||
meta: _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.arrayOf(_react2['default'].PropTypes.string)]))])), | ||
link: _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.arrayOf(_react2['default'].PropTypes.string)]))), | ||
@@ -214,0 +219,0 @@ auto: _react2['default'].PropTypes.objectOf(_react2['default'].PropTypes.bool) |
@@ -23,3 +23,3 @@ /** | ||
target[key] = source[key]; | ||
} else if (typeof target[key] === 'object' && !Array.isArray(target[key])) { | ||
} else if (typeof target[key] === 'object' && !Array.isArray(target[key]) && target[key]) { | ||
defaults(target[key], source[key]); | ||
@@ -26,0 +26,0 @@ } |
{ | ||
"name": "react-document-meta", | ||
"version": "2.0.0-rc1", | ||
"version": "2.0.0-rc2", | ||
"description": "Declarative, nested and stateful HTML document meta tags for React", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42379
941