@@ -14,5 +14,40 @@ describe('Utils', () => {
14
14
const expected = 'An html<br><strong>string</strong>' ;
15
15
expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
16
16
} ) ;
17
+
18
+ it ( 'Strips input tags' , ( ) => {
19
+ const allowedTags = [ 'strong' , 'i' ] ;
20
+ const given = '<p><i>An</i> <strong>input field</strong><input type="button" /></p>' ;
21
+ const expected = '<i>An</i> <strong>input field</strong>' ;
22
+ expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
23
+ } ) ;
24
+
25
+ it ( 'Strips similar tags' , ( ) => {
26
+ const allowedTags = [ 'p' , 'b' , 's' ] ;
27
+ const given = '<sp>Test1</sp> <sssp>Test2</sssp><script></script> <blockquote>quote</blockquote>' ;
28
+ const expected = 'Test1 Test2 quote' ;
29
+ expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
30
+ } ) ;
31
+
32
+ it ( 'Considers whitespaces' , ( ) => {
33
+ const allowedTags = [ 'p' ] ;
34
+ const given = '<p>Test1</ p><p>Test2</ p>' ;
35
+ const expected = '<p>Test1</ p><p>Test2</ p>' ;
36
+ expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
37
+ } ) ;
38
+
39
+ it ( 'Removes all tags with empty allowed tags' , ( ) => {
40
+ const allowedTags = [ ] ;
41
+ const given = '<p>Test1</p> <strong >Test2</strong> < i>Test3</i>' ;
42
+ const expected = 'Test1 Test2 Test3' ;
43
+ expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
44
+ } ) ;
45
+
46
+ it ( 'Removes attributes from html' , ( ) => {
47
+ const allowedTags = [ 'p' ] ;
48
+ const given = '<p data-test="test" title="test2">Test1</p> <strong data-test=\'test2\'>Test2</strong>' ;
49
+ const expected = '<p>Test1</p> Test2' ;
50
+ expect ( utils . sanitizeHTML ( given , allowedTags ) ) . toBe ( expected ) ;
51
+ } ) ;
17
52
} ) ;
18
53
} ) ;
0 commit comments