Skip to content

Commit

Permalink
feat: add tests for Vox.partial/2
Browse files Browse the repository at this point in the history
  • Loading branch information
geolessel committed Sep 17, 2023
1 parent f88c74c commit d910ad3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/support/partials/with-assigns.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="with-assigns">
This should render an assign: <%= @title %>
</div>
3 changes: 3 additions & 0 deletions test/support/partials/without-assigns.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="without-assigns">
This should render without an assign
</div>
20 changes: 20 additions & 0 deletions test/vox_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
defmodule VoxTest do
use ExUnit.Case
doctest Vox

describe "partial/2" do
test "raises without a leading slash for the partial's path" do
assert_raise RuntimeError, fn ->
Vox.partial("improper-path.html.eex")
end
end

test "renders a file with assigns" do
result = Vox.partial("/partials/with-assigns.html.eex", title: "Hello, Vox!")
assert result =~ "id=\"with-assigns\""
assert result =~ "Hello, Vox!"
refute result =~ "@title"
end

test "renders a file without assigns" do
result = Vox.partial("/partials/without-assigns.html.eex")
assert result =~ "id=\"without-assigns\""
end
end
end

0 comments on commit d910ad3

Please sign in to comment.