{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ImplicitParams #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-| Yesod.Test is a pragmatic framework for testing web applications built using wai. By pragmatic I may also mean 'dirty'. Its main goal is to encourage integration and system testing of web applications by making everything /easy to test/. Your tests are like browser sessions that keep track of cookies and the last visited page. You can perform assertions on the content of HTML responses, using CSS selectors to explore the document more easily. You can also easily build requests using forms present in the current page. This is very useful for testing web applications built in yesod, for example, where your forms may have field names generated by the framework or a randomly generated CSRF token input. === Example project The best way to see an example project using yesod-test is to create a scaffolded Yesod project: @stack new projectname yesod-sqlite@ (See https://github.com/commercialhaskell/stack-templates/wiki#yesod for the full list of Yesod templates) The scaffolded project makes your database directly available in tests, so you can use 'runDB' to set up backend pre-conditions, or to assert that your session is having the desired effect. It also handles wiping your database between each test. === Example code The code below should give you a high-level idea of yesod-test's capabilities. Note that it uses helper functions like @withApp@ and @runDB@ from the scaffolded project; these aren't provided by yesod-test. @ spec :: Spec spec = withApp $ do describe \"Homepage\" $ do it "loads the homepage with a valid status code" $ do 'get' HomeR 'statusIs' 200 describe \"Login Form\" $ do it "Only allows dashboard access after logging in" $ do 'get' DashboardR 'statusIs' 401 'get' HomeR -- Assert a \
tag exists on the page 'htmlAnyContain' \"p\" \"Login\" -- yesod-test provides a 'RequestBuilder' monad for building up HTTP requests 'request' $ do -- Lookup the HTML \