There are, as usual, several ways to attack this problem. Before continuing, I urge you to ask yourself why you need it. Such tests are extremely fickle. If you make a small change, it will force you to rewrite the tests that now fail.
However, I think the easiest way to start adding tests that claim the correct rendering is https://github.com/cheeriojs/cheerio
A basic example would look like this:
it ('renders the index page', function(done) { var should = require('should'); var cheerio = require('cheerio'); supertest(app) .get('/') .expect(200) .end(function(err, res) { err.should.not.be.ok(); res.should.be.ok(); var $ = cheerio.load(res.body); var header = $('h1:first'); header.should.equal('Hello World!'); done(); }); )};
Now you wonβt check to see if the rendered view looks exactly the way you want (I mean, you could, but that would be tedious). But it also means that if you make small, minor changes, all of this will not crash. Instead, you can focus on checking that the key aspects of your user interface are displayed correctly (for example, the page name is with the correct spelling and class / identifier properties)
aray12
source share