Test::Mojo attr_ is/isnt/like/unlike

37 views
Skip to first unread message

Karl Boehnker

unread,
Mar 9, 2015, 3:45:17 PM3/9/15
to mojol...@googlegroups.com
Hi,

I sometimes find myself having to test attribute values and would like to see something in Test::Mojo that lets you pass a selector, attrname, and expected value.  I've been using $t->tap(sub{TEST(shift->tx->res->dom->at(SELECTOR)->attr(ATTR), EXPECTED, DESCR)}) which works fine, but is a tad verbose.

Is there a better/lazier way to do this? 

If not, is there any interest in adding attribute testing as a feature? E.g. new methods: attr_is, attr_isnt, attr_like, attr_unlike?

Thanks!

sri

unread,
Mar 9, 2015, 4:23:13 PM3/9/15
to mojol...@googlegroups.com
Is there a better/lazier way to do this?

Attribute selectors come to mind.

    $t->element_exists('a[href="http://example.com/foo"]')
      ->element_exists('a[href="http://example.com/bar"]'); 

--
sebastian

Karl Boehnker

unread,
Mar 9, 2015, 5:13:09 PM3/9/15
to mojol...@googlegroups.com
Indeed, but if your attribute is set to a complex generated value it's not so easy to test with just attribute selectors. In my latest case we have a hidden input field with a bunch of stuff stored in the value attribute. The tests need to get this value and run a number of regexes against it.
Reply all
Reply to author
Forward
0 new messages