travisf

travisf

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!

Showing Posts 1 to 5

cblavier

cblavier

I think that instead of doing

file_input(view, "#profile_pic_upload", ...)

you should do

file_input(view, "#my_form_containing_profile_pic_upload", ...)

Let us know if it works!

travisf

travisf OP

Thanks @cblavier that definitely gets the correct field input.
Now I’m getting an error:

** (exit) exited in: GenServer.call(#PID<0.802.0>, {:chunk, "profile_test.png", 100, #PID<0.800.0>, #Phoenix.LiveViewTest.Element<selector: "#account_form input[type=\"file\"][name=\"profile_pic\"]", text_filter: nil, ...>}, 5000)
 ** (EXIT) shutdown: :closed

But I assume that’s related to something else.

mcrumm

mcrumm

Phoenix Core Team

What version of LiveView are you running currently? In the latest release we should be catching this exit for you.

chrismccord

chrismccord

Creator of Phoenix

Note that you do not need to pass size if you are passing the content, as we’ll calculate the correct byte_size for you. You may be passing a mismatched size which we aren’t handling

travisf

travisf OP

Thank you so much that was the exact issue. I wish I could mark two answers as solutions!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews