Add unit test for sanitize html
This commit is contained in:
parent
95080bd68b
commit
9638b063a0
|
@ -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 = `<html><body><a href="#" malformed="attribute">Link</a></body></html>`;
|
||||||
|
/* eslint-enable quotes */
|
||||||
|
|
||||||
|
test( 'should remove any html tags and attributes which are not allowed', () => {
|
||||||
|
expect( sanitizeHtml( html ) ).toEqual( {
|
||||||
|
__html: '<a href="#">Link</a>',
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
|
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 } );
|
||||||
|
} );
|
||||||
|
} );
|
Loading…
Reference in New Issue