これらの両方が同じ目的を果たしますか?なぜ彼らは両方とも、このチュートリアルhttps://codeforgeek.com/2015/07/unit-testing-nodejs-application-using-mocha/で使用されていますか?Supertest .expect(200)対res.status.should.equal(200);
編集は、次のコードを見てみると:
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);
を持っていることが必要ですか?違いはなんですか?
ようこそスタックオーバーフロー!コードや何かのような努力をして、人々があなたの問題を早期に理解して助けることができるように、あなたの質問を精緻化してください。ありがとう! – manetsus
私の質問を改訂しました。うまくいけばもっと明確です! –