File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
apps/example-app/src/app/examples Expand file tree Collapse file tree 1 file changed +36
-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+ // https://github.com/testing-library/angular-testing-library/pull/271
17+ test ( 'passes HTML as component properties' , async ( ) => {
18+ await render ( `<p>{{ stringWithHtml | stripHTML }}</p>` , {
19+ componentProperties : {
20+ stringWithHtml : STRING_WITH_HTML ,
21+ } ,
22+ declarations : [ StripHTMLPipe ] ,
23+ } ) ;
24+
25+ expect ( screen . getByText ( 'Some database field with stripped HTML' ) ) . toBeInTheDocument ( ) ;
26+ } ) ;
27+
28+
29+ test ( 'throws when passed HTML is passed in directly' , async ( ) => {
30+ await expect ( ( ) =>
31+ render ( `<p data-testid="test"> {{ '${ STRING_WITH_HTML } ' | stripHTML }} </p>` , {
32+ declarations : [ StripHTMLPipe ] ,
33+ } ) ,
34+ ) . rejects . toThrow ( ) ;
35+ } ) ;
36+
You can’t perform that action at this time.
0 commit comments