@@ -172,6 +172,9 @@ defmodule Phoenix.LiveView.EngineTest do
172172 assert changed ( template , % { foo: 123 } , nil ) == [ "123" ]
173173 assert changed ( template , % { foo: 123 } , % { } ) == [ nil ]
174174 assert changed ( template , % { foo: 123 } , % { foo: true } ) == [ "123" ]
175+ assert changed ( template , % { } , % { } ) == [ nil ]
176+ assert changed ( template , % { } , % { foo: true } ) == [ "" ]
177+ assert changed ( template , % { } , % { foo: true } ) == [ "" ]
175178
176179 template = "<%= Access.get(assigns, :foo) %>"
177180 assert changed ( template , % { foo: 123 } , nil ) == [ "123" ]
@@ -268,6 +271,21 @@ defmodule Phoenix.LiveView.EngineTest do
268271 assert changed ( template , new_changed_bar , old ) == [ "777" ]
269272 end
270273
274+ test "map access with non existing key" do
275+ template = "<%= @map[:baz] || \" default\" %>"
276+ old = % { map: % { foo: 123 , bar: 456 } }
277+ new_augmented = % { map: % { foo: 123 , bar: 456 , baz: 789 } }
278+ new_changed_foo = % { map: % { foo: 321 , bar: 456 } }
279+ new_changed_bar = % { map: % { foo: 123 , bar: 654 } }
280+ assert changed ( template , old , nil ) == [ "default" ]
281+ assert changed ( template , old , % { } ) == [ nil ]
282+ assert changed ( template , old , % { map: true } ) == [ "default" ]
283+ assert changed ( template , new_augmented , old ) == [ "789" ]
284+ # no re-render when the key is still not present
285+ assert changed ( template , new_changed_foo , old ) == [ nil ]
286+ assert changed ( template , new_changed_bar , old ) == [ nil ]
287+ end
288+
271289 test "renders dynamic with access tracking for forms" do
272290 form1 = Phoenix.Component . to_form ( % { "foo" => "bar" } )
273291 form2 = Phoenix.Component . to_form ( % { "foo" => "bar" , "baz" => "bat" } )
0 commit comments