Skip to content

Commit

Permalink
feat: add tests for Vox.partial/2 (#44)
Browse files Browse the repository at this point in the history
Adds tests for `Vox.partial/2`. I anticipate very quickly refactoring
this so that the ultimate call isn't made to
`Vox.Builder.FileCompiler.partial/2`. I'd like to put that somewhere
else. But these tests will help me have confidence in that refactoring.

Progresses #31
  • Loading branch information
geolessel authored Sep 17, 2023
2 parents f88c74c + d910ad3 commit 0871358
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 0871358

Please sign in to comment.