O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Views and Templates

As we’ve said, any code worth writing is code worth testing, and your views are no exception. As you saw in Chapter 3, Controllers, Views, and Templates, Phoenix templates are simply functions in a parent’s view module. You can test these functions like any other. In this section, you’ll see how to test views and templates in isolation.

Create a test/views/video_view_test.exs and key this in:

1: defmodule​ Rumbl.VideoViewTest ​do
use​ Rumbl.ConnCase, ​async:​ true
import​ Phoenix.View
5:  test ​"​​renders index.html"​, %{​conn:​ conn} ​do
videos = [%Rumbl.Video{​id:​ ​"​​1"​, ​title:​ ​"​​dogs"​},
%Rumbl.Video{​id:​ ​"​​2"​, ​title:​ ​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required