UNPKG

@bnnvara/typography

Version:

Typography for BNNVARA

53 lines (44 loc) 2.77 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _build = require("enzyme/build"); var _withHtmlSafe = _interopRequireDefault(require("./withHtmlSafe")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var MockComponent = function MockComponent(_ref) { var children = _ref.children, props = _objectWithoutProperties(_ref, ["children"]); return _react.default.createElement("div", props, children); }; var HtmlSafeComponent = (0, _withHtmlSafe.default)(MockComponent); describe('withHtmlSafe', function () { it('should be defined', function () { expect(_withHtmlSafe.default).toBeDefined(); }); it('should have an enhanced component defined', function () { expect(HtmlSafeComponent).toBeDefined(); }); it('should render escaped HTML', function () { var content = '<p>Some content</p>'; expect((0, _build.render)(_react.default.createElement(HtmlSafeComponent, null, content)).html()).toMatch('&lt;p&gt;Some content&lt;/p&gt;'); }); it('should render HTML', function () { var content = '<p>Some content</p>'; expect((0, _build.render)(_react.default.createElement(HtmlSafeComponent, { html: true }, content)).html()).toMatch('<p>Some content</p>'); }); it('should render only allowed tags', function () { var content = "<p>Some <strong>content</strong> and <i>other</i> <em>content</em></p>"; expect((0, _build.render)(_react.default.createElement(HtmlSafeComponent, { html: true, allowedTags: ['strong', 'em'] }, content)).html()).toMatch('Some <strong>content</strong> and other <em>content</em>'); }); it('should render strip out <script> tags', function () { var content = "<p>Some content</p><script>alert('hello')</script>"; expect((0, _build.mount)(_react.default.createElement(HtmlSafeComponent, { html: true }, content)).html()).toMatch('<p>Some content</p>'); }); });