I’m trying to test a file upload:
file =
file_input(view, "#profile_pic_upload", :profile_pic, [
%{
last_modified: '1_624_366_053_000',
name: "profile_test.png",
content: File.read!("../support/profile_test.png"),
size: 269_280,
type: "image/png"
}
])
assert render_upload(file, "foo.png") =~ "100%"
But I keep getting this error:
** (ArgumentError) expected selector "#profile_pic_upload input[type=\"file\"][name=\"profile_pic\"]" to return a single element, but got none within:
But the HTML returned seems to contain that specific element:
<input accept=".jpg,.jpeg,.png" data-phx-active-refs="" data-phx-done-refs="" data-phx-preflighted-refs="" data-phx-update="ignore" data-phx-upload-ref="phx-Fors3j71WxhLhgGi" id="profile_pic_upload" name="profile_pic" phx-hook="Phoenix.LiveFileUpload" type="file"/>
So why is it unable to find the selector? Is there something I need to do to be more explicit?
For some context, I’m not actually trying to test the upload percentage, I’m just working through the docs. I am trying to populate the field with a file, submit the form to test some logic that my LiveView performs when a profile is updated with a profile picture. If there is another way to submit a form with a file attached, or fake it, I’m all ears!