Skip to content

Commit a9237f2

Browse files
test: add test case for #269 (#271)
Closes #269
1 parent 4e766d1 commit a9237f2

File tree

1 file changed

+36
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)