samedi 30 novembre 2019

Why NodeJS test framework like supertest needs the instance of the server?

Why NodeJS test framework like supertest needs the instance of the server to execute api calls?

From their example:

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

const app = express();

app.get('/user', function(req, res) {
  res.status(200).json({ name: 'john' });
});

request(app)
  .get('/user')
  .expect('Content-Type', /json/)
  .expect('Content-Length', '15')
  .expect(200)
  .end(function(err, res) {
    if (err) throw err;
  });

As an alternative, why can't they use Axios? What is the advantage of using my web-server instance?

Aucun commentaire:

Enregistrer un commentaire