From 9638b063a094387232894aa89d5f3063056317b8 Mon Sep 17 00:00:00 2001 From: Allen Snook Date: Tue, 16 Oct 2018 15:54:33 -0700 Subject: [PATCH] Add unit test for sanitize html --- .../client/lib/sanitize-html/test/index.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugins/woocommerce-admin/client/lib/sanitize-html/test/index.js diff --git a/plugins/woocommerce-admin/client/lib/sanitize-html/test/index.js b/plugins/woocommerce-admin/client/lib/sanitize-html/test/index.js new file mode 100644 index 00000000000..f91b72fa50d --- /dev/null +++ b/plugins/woocommerce-admin/client/lib/sanitize-html/test/index.js @@ -0,0 +1,33 @@ +/** + * @format + * @jest-environment jsdom + */ + +/** + * External dependencies + */ +import dompurify from 'dompurify'; + +/** + * Internal dependencies + */ +import sanitizeHtml, { ALLOWED_TAGS, ALLOWED_ATTR } from '../../sanitize-html'; + +describe( 'sanitizeHtml', () => { + /* eslint-disable quotes */ + const html = `Link`; + /* eslint-enable quotes */ + + test( 'should remove any html tags and attributes which are not allowed', () => { + expect( sanitizeHtml( html ) ).toEqual( { + __html: 'Link', + } ); + } ); + + test( 'should call dompurify.sanitize with list of allowed tags and attributes', () => { + const sanitizeMock = jest.spyOn( dompurify, 'sanitize' ); + + sanitizeHtml( html ); + expect( sanitizeMock ).toHaveBeenCalledWith( html, { ALLOWED_ATTR, ALLOWED_TAGS } ); + } ); +} );