File tree 1 file changed +34
-0
lines changed
apps/example-app/src/app/issues
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { render , screen } from '@testing-library/angular' ;
2
+ import { Pipe , PipeTransform } from '@angular/core' ;
3
+
4
+ @Pipe ( {
5
+ name : 'stripHTML' ,
6
+ } )
7
+ class StripHTMLPipe implements PipeTransform {
8
+ transform ( stringValueWithHTML : string ) : string {
9
+ return stringValueWithHTML . replace ( / < [ ^ > ] * > ? / gm, '' ) ;
10
+ }
11
+ }
12
+
13
+ const STRING_WITH_HTML =
14
+ 'Some <em>database</em> <b>field</b> <div><span>with <strong>stripped</strong> HTML</span></div>' ;
15
+
16
+ test ( 'should strip the HTML from a string' , async ( ) => {
17
+ await expect ( ( ) =>
18
+ render ( `<p data-testid="test"> {{ '${ STRING_WITH_HTML } ' | stripHTML }} </p>` , {
19
+ declarations : [ StripHTMLPipe ] ,
20
+ } ) ,
21
+ ) . rejects . toThrow ( ) ;
22
+ } ) ;
23
+
24
+ test ( 'workaround should strip the HTML from a string' , async ( ) => {
25
+ await render ( `<p data-testid="test">{{ stringWithHtml | stripHTML }}</p>` , {
26
+ componentProperties : {
27
+ stringWithHtml : STRING_WITH_HTML ,
28
+ } ,
29
+ declarations : [ StripHTMLPipe ] ,
30
+ } ) ;
31
+
32
+ const testControl = screen . getByTestId ( 'test' ) ;
33
+ expect ( testControl ) . toHaveTextContent ( 'Some database field with stripped HTML' ) ;
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments