Skip to content

Commit 02531a6

Browse files
committed
test: add test case for #269
1 parent 6ea2e7f commit 02531a6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
});

0 commit comments

Comments
 (0)