diff --git a/client/components/banner/index.jsx b/client/components/banner/index.jsx index 2b0f4a7f00160..a286bef7e0576 100644 --- a/client/components/banner/index.jsx +++ b/client/components/banner/index.jsx @@ -12,6 +12,7 @@ import { Button, Card, Gridicon } from '@automattic/components'; import { isMobile } from '@automattic/viewport'; import classNames from 'classnames'; import DOMPurify from 'dompurify'; +import { JSDOM } from 'jsdom'; import { size } from 'lodash'; import PropTypes from 'prop-types'; import { Component } from 'react'; @@ -182,6 +183,16 @@ export class Banner extends Component { ); } + sanitize( html ) { + // Getting an instance of DOMPurify this way is needed to fix a related JEST test. + const { window } = new JSDOM( '' ); + const domPurify = DOMPurify( window ); + return domPurify.sanitize( html, { + ALLOWED_TAGS: [ 'a' ], + ALLOWED_ATTR: [ 'href', 'target' ], + } ); + } + getContent() { const { callToAction, @@ -203,11 +214,6 @@ export class Banner extends Component { const prices = Array.isArray( price ) ? price : [ price ]; - const sanitizedDescription = DOMPurify.sanitize( description, { - ALLOWED_TAGS: [ 'a' ], - ALLOWED_ATTR: [ 'href', 'target' ], - } ); - return (