Skip to content

Instantly share code, notes, and snippets.

@jwo
Created July 10, 2017 14:40
Show Gist options
  • Save jwo/77656e9945cb3fe426b535c97889f554 to your computer and use it in GitHub Desktop.
Save jwo/77656e9945cb3fe426b535c97889f554 to your computer and use it in GitHub Desktop.
Simple example for testing an HTML endpoint in node with supertest and chai. Most examples only test API endpoints it seems.
const express = require("express");
const mustache = require("mustache-express");
const bodyParser = require("body-parser");
const app = express();
// Rest of the stuff here
// DONT FORGET THIS
module.exports = app;
const request = require("supertest");
const assert = require("chai").assert;
const app = require("../app");
describe("GET /", function(){
it("is 200", function(done){
request(app)
.get("/")
.expect("Content-type",/html/)
.expect(200)
.end(function(err, res){
assert.include(res.text, "Games")
done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment