![]() The option to use an element is failing due to the wrong query selector. Earlier on, I mentioned that open_browser/2 could either take in a view or an element. ![]() In the test, we shall call open_browser/2 and pass the view returned after invoking live/2 to it. The other option is to debug the LiveView page where the registration form is rendered. Just like the render/1 function, open_browser/2 expects the form element with the query selector #wrong_registration-form passed to it, but it doesn't exist. This way, we expect the browser to open with the displayed registration form - but apparently, that won't be the case when we run our test. LiveViewTest test "user can see registration form", %) |> open_browser () |> render () end end RegistrationLiveTest do use SamplLiveWeb. # test/sample_live_web/registration_live_test.exs defmodule SampleLiveWeb. This feature will only focus on the rendered HTML and not include the ability to add users into the system (the backend part of taking user params and adding them into the data store).įirst, start by creating a new LiveView application: We shall add a form to our application that allows users to enter their email address and password when attempting to register. Let's write a sample feature to use as our testing example. The test helpers assist us in writing meaningful tests for our LiveView modules with ease and speed. You can test the functionality of your live views' behavior through the help of the Phoenix.LiveViewTest module, which offers convenient functions without the need to introduce JS testing frameworks. ![]() We can be confident in writing LiveView tests that are fast, concurrent, and stable. The ability to easily write meaningful tests is an important factor for any framework, regardless of programming language.ĭevelopers can easily test the LiveView framework's component, life-cycle, and behavior by writing LiveView tests with pure Elixir, since it uses ExUnit (a built-in testing framework) for all its testing. Testing during the software development process is one way to build confidence and ensure your application will work as expected. Let's get started! Introducing LiveView Testing In addition, we'll give a brief introduction to testing LiveView. In this blog post, you'll see how useful open_browser/2 is when debugging LiveView tests.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |