이것은 mongoDB 드라이버 문서의 예제입니다. 나는 assert.equal이 예제에서 무엇을하는지 알아 내려고 노력했지만 Node.js 웹 사이트의 공식 문서는 나에게 너무 도움이되지 않았다. - 공식 문서에는 "동등한 비교 연산자를 사용하여 얕고 강제적 인 평등을 테스트한다. (==). " 그래서 저는 그것이 평등의 진리 가치에 따라 진실 또는 거짓을 돌려 줄 것이라고 처음에 의심했습니다. 그러나 그렇지 않은 것처럼 보입니다.node.js mongodb 드라이버 문서의 assert 모듈
나는이 게시물을 보았다 : Assert module use in nodejs?. 도움이되었지만 충분하지 않았습니다. 나는 아직도 "단위 테스트"가 어떻게 수행되는지 이해하지 못한다. 어떤 도움도 감사 하겠지만 견고한 예가 도움이 될 것입니다!
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
// Set up the connection to the local db
var mongoclient = new MongoClient(new Server("localhost", 27017), {native_parser: true});
// Open the connection to the server
mongoclient.open(function(err, mongoclient) {
// Get the first db and do an update document on it
var db = mongoclient.db("integration_tests");
db.collection('mongoclient_test').update({a:1}, {b:1}, {upsert:true}, function(err, result) {
assert.equal(null, err);
assert.equal(1, result);
// Get another db and do an update document on it
var db2 = mongoclient.db("integration_tests2");
db2.collection('mongoclient_test').update({a:1}, {b:1}, {upsert:true}, function(err, result) {
assert.equal(null, err);
assert.equal(1, result);
// Close the connection
mongoclient.close();
});
});
});
제 생각에는 ... 프로그램이 실행을 멈추고 어설 션이 사실이 아닐 때 오류 메시지를 던집니까? – Channy