我正在关注Esposito 的 Yesod 教程并尝试围绕 Mirror 示例进行测试。
我的测试来自以下HomeTest.hs文件中的文件yesod init:
{-# LANGUAGE OverloadedStrings #-}
module MirrorTest
( mirrorSpecs
) where
import TestImport
import qualified Data.List as L
mirrorSpecs :: Spec
mirrorSpecs =
ydescribe "This tests the sample mirror feature" $ do
yit "loads the mirror page and checks it has correct elements" $ do
get MirrorR
statusIs 200
htmlAllContain "h1" "Mirror test"
htmlAllContain "label" "Enter your text"
request $ do
setMethod "POST"
setUrl MirrorR
byLabel "Enter your text" "wooo"
statusIs 200
printBody
htmlCount ".p" 1
htmlAllContain ".h1" "You posted"
htmlAllContain ".p" "woooooow"
htmlAllContain ".p" "text/plain"
同时我的mirror.hamlet文件是:
<h1> Mirror test
<form method=post action=@{MirrorR}>
<label for=content>Enter your text
<input type=text name=content>
<input type=submit>
但我得到的测试输出是:
1) This tests the sample mirror feature loads the mirror page and checks it has correct elements
More than one input with id content
我很困惑:只有一个输入具有内容名称,而多个元素具有该名称,但据我回忆,名称不一定是唯一的(与实际ids不同)。我是否需要使用Yesod.Test.TransversingCSS来完成我想要在这里做的事情,通过给输入一个实际的 id?
我的 Haskell 仍然很弱,所以我可能遗漏了明显的内容,非常感谢如何在 Yesod 中实现测试的示例。