dimanche 31 janvier 2016

can i run unit tests with super test to check the rout in my app.js file

I am new to node and express. is it ok to run unit test this way.for a basic hello world app. if yes, how should the the path be at

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

Here is what i am trying out:

var express = require('express');
var request = require('supertest');

var app = express();
var router = express.Router();

app.get('/somename', function(req, res){
  res.status(200);
});

request(app)
 .get('/somename')
  .expect('Content-Type', /json/)

  .expect(200)
  .end(function(err, res){
    if (err) throw err;
  });


router.get('/', function (req, res){
res.send(' { “Hello”: “World” }');
});

router.get('/a', function (req, res){
res.send(' { “Hello”: “World” }');
});

app.use('/somename', router)

app.listen(4000);

I am using express 4.

Aucun commentaire:

Enregistrer un commentaire