【发布时间】:2016-07-26 02:06:04
【问题描述】:
这两者的目的是否相同?为什么它们都用在例如本教程https://codeforgeek.com/2015/07/unit-testing-nodejs-application-using-mocha/ 中?
编辑,看下面的代码:
var supertest = require("supertest");
var should = require("should");
// This agent refers to PORT where program is runninng.
var server = supertest.agent("http://localhost:3000");
// UNIT test begin
describe("SAMPLE unit test",function(){
// #1 should return home page
it("should return home page",function(done){
// calling home page api
server
.get("/")
.expect("Content-type",/json/)
.expect(200) // THis is HTTP response
.end(function(err,res){
// HTTP status should be 200
res.status.should.equal(200);
// Error key should be false.
res.body.error.should.equal(false);
done();
});
});
});
有没有必要
.expect(200)
和
res.status.should.equal(200);
?有什么区别?
【问题讨论】:
-
欢迎来到 Stack Overflow!您能否详细说明您的问题,例如代码或其他东西,以便人们可以及早解决您的问题并为您提供帮助?谢谢!
-
修改了我的问题,希望更清楚!