yesod-test : Add htmlNoneContain (logical inverse of htmlAnyContain).

This commit is contained in:
Erik de Castro Lopo 2014-05-28 22:51:04 +10:00
parent f0d6e1adaa
commit 7318d47781

View File

@ -75,6 +75,7 @@ module Yesod.Test
, bodyContains
, htmlAllContain
, htmlAnyContain
, htmlNoneContain
, htmlCount
-- * Grab information
@ -353,6 +354,19 @@ htmlAnyContain query search = do
_ -> liftIO $ HUnit.assertBool ("None of "++T.unpack query++" contain "++search) $
DL.any (DL.isInfixOf search) (map (TL.unpack . decodeUtf8) matches)
-- | Queries the html using a css selector, and fails if any matched
-- element contains the given string (in other words, it is the logical
-- inverse of htmlAnyContains).
--
-- Since 1.2.1.6
htmlNoneContain :: Query -> String -> YesodExample site ()
htmlNoneContain query search = do
matches <- htmlQuery query
case DL.filter (DL.isInfixOf search) (map (TL.unpack . decodeUtf8) matches) of
[] -> return ()
found -> failure $ "Found " <> T.pack (show $ length found) <>
" instances of " <> T.pack search <> " in " <> query <> " elements"
-- | Performs a css query on the last response and asserts the matched elements
-- are as many as expected.
htmlCount :: Query -> Int -> YesodExample site ()