summary refs log tree commit diff stats
path: root/test/app.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/app.test.js')
-rw-r--r--test/app.test.js29
1 files changed, 23 insertions, 6 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 => {