我正在尝试使用mocha和chai编写单元测试,我面临的主要问题是,对于每个API,我必须专门定义url,即
test.js
var expect = require('chai').expect;
var should = require('chai').should;
var express = require('express');
var chai = require('chai');
var chaiHttp = require('chai-http');
chai.use(chaiHttp);
var baseUrl = 'http://localhost:3000/api';
describe("Test case for getting all the users", function(){
it("Running test", function(done){
this.timeout(10000); //to check if the API is taking too much time to return the response.
var url = baseUrl + '/v1/users?access_token=fd085c73227b94fb3d1d5552b5a62be963b6d068'
chai.request(url)
.get('')
.end(function(err, res) {
//console.log('routes>>>>', routes);
expect(err).to.be.null;
expect(res.statusCode).to.equal(200); // <= Call done to signal callback end
expect(res).to.have.property('text');
done();
});
}); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将两个网址合并为一个网址。
var access_token = 138def4a4e;
var url = "https://graph.facebook.com/app/?access_token=";
Run Code Online (Sandbox Code Playgroud)
我希望最终的网址是:
url = "https://graph.facebook.com/app/?access_token=[access_token]";
Run Code Online (Sandbox Code Playgroud)
如何在 Node.js 中做到这一点?我尝试使用网址。解决了,但是没有用。
请帮助TIA