diff options
author | Alan Pearce | 2017-06-30 18:01:51 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-30 18:01:51 +0200 |
commit | 31f441ff32ab9f52fc80d0835bdd074554587ef6 (patch) | |
tree | 2414dc886efcb783352c1857dc6a4a2fd60ce41e /test | |
parent | 562b0533300ad5ad8cf4695aa7fc2b844b918169 (diff) | |
download | homestead-31f441ff32ab9f52fc80d0835bdd074554587ef6.tar.lz homestead-31f441ff32ab9f52fc80d0835bdd074554587ef6.tar.zst homestead-31f441ff32ab9f52fc80d0835bdd074554587ef6.zip |
test: Use cheerio for DOM testing
Diffstat (limited to 'test')
-rw-r--r-- | test/app.test.js | 29 | ||||
-rw-r--r-- | test/testsite/posts/testfile.md | 4 |
2 files changed, 26 insertions, 7 deletions
diff --git a/test/app.test.js b/test/app.test.js index 9b0403c..8507c41 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,28 +1,45 @@ const test = require("ava"); const path = require("path"); const request = require("supertest"); +const cheerio = require("cheerio"); process.chdir(path.resolve(__dirname, "./testsite/")); const config = require(path.resolve(__dirname, "../src/modules/config.js")); const app = require("../src/app.js"); +const parseResponse = res => + cheerio.load(res.text, { + normalizeWhitespace: true, + useHtmlParser2: true + }); + test("homepage", t => { return request(app.listen()) .get("/") .expect(200) - .expect(/<title>Test Site<\/title>/) - .expect(/<h1>Test Site<\/h1>/) - .expect(/This is a test/) - .then(() => t.pass()); + .then(parseResponse) + .then($ => { + t.is($("head > title").text(), config.site.title); + t.is($("h1").text(), config.site.title); + t.is($("main").length, 1); + }); }); test("post", t => { return request(app.listen()) .get("/post/testfile") .expect(200) - .expect(/<h1>Lorem ipsum<\/h1>/) - .then(() => t.pass()); + .then(parseResponse) + .then($ => { + t.is($("article h1").text(), "This is a test"); + t.is( + $("article p").text(), + `Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat \ +velit, scelerisque in dictum non, consectetur a erat nam at lectus \ +urna duis convallis convallis tellus, id interdum velit laoreet!` + ); + }); }); test("post not found", t => { diff --git a/test/testsite/posts/testfile.md b/test/testsite/posts/testfile.md index bafc456..65f2122 100644 --- a/test/testsite/posts/testfile.md +++ b/test/testsite/posts/testfile.md @@ -3,4 +3,6 @@ Title = "This is a test" Description = "Test file" Tags = ["a", "b"] +++ -# Lorem ipsum +Ut enim blandit volutpat maecenas? Volutpat blandit aliquam etiam erat +velit, scelerisque in dictum non, consectetur a erat nam at lectus +urna duis convallis convallis tellus, id interdum velit laoreet! |