From b8c12aadcd9a72f26818b2cfc9887317ada058be Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 2 Jun 2021 12:04:36 +0800 Subject: [PATCH] add test --- test/bootstrap.js | 15 +++++++++++++++ test/mocha.opts | 5 +++++ test/spec/array.spec.js | 8 ++++++++ test/spec/demo.spec.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 test/bootstrap.js create mode 100644 test/mocha.opts create mode 100644 test/spec/array.spec.js create mode 100644 test/spec/demo.spec.js diff --git a/test/bootstrap.js b/test/bootstrap.js new file mode 100644 index 0000000..57bc276 --- /dev/null +++ b/test/bootstrap.js @@ -0,0 +1,15 @@ +before(function(done) { + this.timeout(0); + var app = app || require("../app"); + + global.app = app; + done(); +}); + +after(function(done) { + console.log(); + console.log("--------------------"); + console.log("Test Completely!!"); + console.log("--------------------"); + done(); +}); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..92b671d --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,5 @@ +--timeout 500000 +--require should +--reporter spec +--ui bdd +--recursive ./app.js diff --git a/test/spec/array.spec.js b/test/spec/array.spec.js new file mode 100644 index 0000000..d514cb8 --- /dev/null +++ b/test/spec/array.spec.js @@ -0,0 +1,8 @@ +const assert = require("assert"); +describe("Array", () => { + describe("#indexOf()", () => { + it("should return -1 when the value is not present", function() { + assert.equal(-1, [1, 2, 3].indexOf(4)); + }); + }); +}); diff --git a/test/spec/demo.spec.js b/test/spec/demo.spec.js new file mode 100644 index 0000000..ce38b97 --- /dev/null +++ b/test/spec/demo.spec.js @@ -0,0 +1,28 @@ +require("../bootstrap"); + +const should = require("should"); +const request = require("supertest"); + +describe("Test Index,", () => { + it("Should get 200 response.", done => { + request(app) + .get("/") + .expect(200) + .expect("Content-Type", /html/) + .end(done); + }); +}); + +describe("GET /users", () => { + it("respond with json", done => { + request(app) + .get("/user") + .set("Accept", "application/json") + .expect(200) + .expect("Content-Type", /json/) + .end((err, res) => { + if (err) return done(err); + done(); + }); + }); +});