diff --git a/apps/example-app/src/app/examples/18-html-as-input.spec.ts b/apps/example-app/src/app/examples/18-html-as-input.spec.ts new file mode 100644 index 00000000..5a56b412 --- /dev/null +++ b/apps/example-app/src/app/examples/18-html-as-input.spec.ts @@ -0,0 +1,36 @@ +import { render, screen } from '@testing-library/angular'; +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'stripHTML', +}) +class StripHTMLPipe implements PipeTransform { + transform(stringValueWithHTML: string): string { + return stringValueWithHTML.replace(/<[^>]*>?/gm, ''); + } +} + +const STRING_WITH_HTML = + 'Some database field
with stripped HTML
'; + +// https://github.com/testing-library/angular-testing-library/pull/271 +test('passes HTML as component properties', async () => { + await render(`

{{ stringWithHtml | stripHTML }}

`, { + componentProperties: { + stringWithHtml: STRING_WITH_HTML, + }, + declarations: [StripHTMLPipe], + }); + + expect(screen.getByText('Some database field with stripped HTML')).toBeInTheDocument(); +}); + + +test('throws when passed HTML is passed in directly', async () => { + await expect(() => + render(`

{{ '${STRING_WITH_HTML}' | stripHTML }}

`, { + declarations: [StripHTMLPipe], + }), + ).rejects.toThrow(); +}); +