Skip to content

Commit

Permalink
add tests for overriding vite_asset attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Niicck committed Oct 23, 2023
1 parent da7ee1b commit aeb31c0
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/tests/templatetags/test_vite_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,57 @@ def test_vite_asset_production_staticfiles_storage(patch_settings):
assert script_tag["type"] == "module"
links = soup.find_all("link")
assert len(links) == 13


@pytest.mark.usefixtures("patch_dev_mode_false")
def test_vite_asset_override_default_production_attribute():
template = Template(
"""
{% load django_vite %}
{% vite_asset "src/entry.ts" crossorigin="anonymous" %}
"""
)
html = template.render(Context({}))
soup = BeautifulSoup(html, "html.parser")
script_tag = soup.find("script")
assert script_tag["crossorigin"] == "anonymous"


@pytest.mark.parametrize(
"patch_settings",
[
{
"DJANGO_VITE_DEV_MODE": False,
},
{
"DJANGO_VITE_DEV_MODE": True,
},
{
"DJANGO_VITE": {
"default": {
"dev_mode": False,
}
}
},
{
"DJANGO_VITE": {
"default": {
"dev_mode": True,
}
}
},
],
indirect=True,
)
def test_vite_asset_custom_attributes(patch_settings):
template = Template(
"""
{% load django_vite %}
{% vite_asset "src/entry.ts" foo="bar" hello="world" %}
"""
)
html = template.render(Context({}))
soup = BeautifulSoup(html, "html.parser")
script_tag = soup.find("script")
assert script_tag["foo"] == "bar"
assert script_tag["hello"] == "world"

0 comments on commit aeb31c0

Please sign in to comment.