samedi 29 juin 2019

Test Jasmine returns undefined for response

I have written a node JS application where I am passing in my mongoDB url. Via the process.env, I am able to parse my mongoDB url into my js. The reason for this is I do not wish to hardcode my mongoDB ip. It should be able to swap out at any point of time for another mongoDB database hosted in a separate infrastructure environment. i.e MONGODB_URL='mongodb://localhost:27017/user' npm start

I am writing a test case for this using jasmine-node, however, when I try to do MONGODB_URL='mongodb://localhost:27017/user' npm test, it doesnt seem that any test cases are running and it returns an undefined for my response.

This is my github repo for my code https://github.com/leeadh/node-jenkins-app-example in the development branch.

Does anyone know what is the cause or how I should have written it?

Thank you

var request = require("request");
var base_url = "http://localhost:4000/";
var server = require("../app.js");


// sample unit test begin
describe("Test Base Page", function() {
  describe("GET /", function() {
    it("returns status code 200", function(done) {
      request.get("http://localhost:4000/", function(error, response, body) {
        console.log("example")
        console.log(response)
        expect(response.statusCode).toBe(200);
        done();
        server.close()
      });
    });

  });
});


Aucun commentaire:

Enregistrer un commentaire