does anybody know of an extension of shouldjs or some other assertion library which helps to assert the response stream for html tags.
I would like to write some acceptance test like
body.should.contain.link 'login'
or
body.should.contain.h1 'Hello world'
Just an example that came up to my mind which could be pretty handy...
Or how do you guys test your response...?
Thanks
The Chai Assertion Library has a plugin that you might be interested in, though that exact markup is not supported.
First off, if your testing in the browser there is chai-jquery. It would allow you to do things like this:
$('body').should.have('h1.title').text('Hello world');
From the looks of your snippet, your testing on the server side, which makes things a bit more complicated. We had attempted to get chai-jquery working for node by using jsdom to parse the html returned from a server and loading it into a jquery object to test on, but jsdom doesn't play well with jQuery.
The alternative that I have seen (but have yet to try) is cherio. It seems to behave more like jQuery is expected to. In which case, you could do something like this (untested)...
$('h1', body).text().should.contain('Hello universe');
Hope that is enough to get you started.