This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/test/parser/slot_test.exs
Mitchell Hanberg 851f6415fe Slots!
Integration test for slots

Format integration test project

Hide slots assign in temple prefixed key

Won't compile temple related assigns when calling Utils.runtime_attrs

Update component docs with slots usage
2021-05-13 00:21:43 -04:00

48 lines
1 KiB
Elixir

defmodule Temple.Parser.SlotTest do
use ExUnit.Case, async: false
alias Temple.Parser.Slot
describe "applicable?/1" do
test "runs when using the `c` ast with a block" do
ast =
quote do
slot :header, value: "yolo"
end
assert Slot.applicable?(ast)
end
end
describe "run/2" do
test "adds a node to the buffer" do
raw_ast =
quote do
slot :header, value: "yolo"
end
ast = Slot.run(raw_ast)
assert %Slot{
name: :header,
args: [value: "yolo"]
} == ast
end
end
describe "Temple.Generator.to_eex/1" do
test "emits eex for a slot" do
raw_ast =
quote do
slot :header, value: Form.form_for(changeset, action)
end
result =
raw_ast
|> Slot.run()
|> Temple.Generator.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s|<%= @__temple_slots__.header.(Enum.into([value: Form.form_for(changeset, action)], %{})) %>|
end
end
end