<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="347188" data-post-id="347188">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dustin" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dustin
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This appears to work for me:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">test "connected mount", %{conn: conn} do
  {:ok, view, _html} = live(conn, "/my-path")
  assert view.assigns[:some_key] == expected_value
end
</code></pre>
<p>The reason I want to do this is that I have a parent LiveView with a couple of children. I want to send a message to a child to refresh when something happens in the parent. To do this, I need the child to have a unique ID so I can send it a message without sending that message to other children on the server with that same id (pretty sure this is how it works?). I don’t want to load the data in the parent because the children are somewhat complicated and the code is nice if they load their own data.</p>
<p>In the LiveView test, I need access to the child using <code>find_live_child</code> and to do that I need its id. Which is stored in the assigns.</p>
<p>I wrote all that up because I think it’s a valid reason to need access to the assigns, and also because maybe my overall approach isn’t right and someone can tell me.</p>
<p>Update: I’m going to have the child LiveView register with its parent instead of looking up the pid. I think this will be more elegant and make it so I don’t need that unique id on the child.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="347188" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/accessing-assigns-in-liveview-test/28463/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-347188" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="347188"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="348887" data-post-id="348887">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lccezinha" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lccezinha/120/20227_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lccezinha
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>:sys.get_state(view.pid).assigns</p>
<p>I can be wrong, but I think you can do something like that (syntax may be wrong)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="348887" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/accessing-assigns-in-liveview-test/28463/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-348887" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348887"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="363310" data-post-id="363310">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="EasterPeanut" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  EasterPeanut
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>For anyone reaching this forum post because they wanted to test a part of a LiveView / Live Component, for example the ‘handle_event/3’ implementation, this is how I wrote one of my tests:</p>
<pre data-code-wrap="ex"><code class="lang-ex">    test "raises an error if user is not authorized to delete the upload",
         %{conn: conn, user: user} do
      recipe = insert(:recipe, status: :draft, author: user, cover_image: insert(:cover_image))

      socket = %Phoenix.Socket{} |&gt; Phoenix.Socket.assign(recipe: recipe)

      assert_raise MyApp.Media.NotAuthorizedError, "not authorized", fn -&gt;
        BadgerWeb.Recipes.CoverImageUploadComponent.handle_event("delete-upload", %{}, socket)
      end
    end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="363310" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/accessing-assigns-in-liveview-test/28463/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-363310" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="363310"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>