Skip to content

Commit 84e9bee

Browse files
committed
test: add tests for extract_text_from_html function
1 parent a42ad8f commit 84e9bee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
has_return_outside_function,
1414
is_script_already_function,
1515
validate_browser_paths,
16+
extract_text_from_html,
1617
)
1718

1819

@@ -401,3 +402,26 @@ def test_has_return_outside_function_arrow_function(self):
401402
'''
402403
assert has_return_outside_function(script) is False
403404

405+
def test_extract_text_without_strip_without_separator(self):
406+
html = ('<div>Hello <span> world </span><script>alert(1)</script><style>body { color: red; }</style>'
407+
'<template>hidden</template></div>')
408+
result = extract_text_from_html(html)
409+
assert result == 'Hello world '
410+
411+
def test_extract_text_with_strip_without_separator(self):
412+
html = ('<div>Hello <span> world </span><script>alert(1)</script><style>body { color: red; }</style>'
413+
'<template>hidden</template></div>')
414+
result = extract_text_from_html(html, strip=True)
415+
assert result == 'Helloworld'
416+
417+
def test_extract_text_without_strip_with_separator(self):
418+
html = ('<div>Hello <span> world </span><script>alert(1)</script><style>body { color: red; }</style>'
419+
'<template>hidden</template></div>')
420+
result = extract_text_from_html(html, separator="/")
421+
assert result == 'Hello / world '
422+
423+
def test_extract_text_with_strip_with_separator(self):
424+
html = ('<div>Hello <span> world </span><script>alert(1)</script><style>body { color: red; }</style>'
425+
'<template>hidden</template></div>')
426+
result = extract_text_from_html(html, strip=True, separator="/")
427+
assert result == 'Hello/world'

0 commit comments

Comments
 (0)