mocha를 사용하여 테스트 및 REST API를 원하므로 생성 작업을 테스트하는 다음 코드가 있습니다.
'use strict';
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var winston = require('winston');
describe('Routing', function() {
describe('asset', function() {
it('Crear un nuevo activo en la base de datos y retornarlo', function(done) {
var asset = {
"description" : "Computador portatil",
"maker" : "Lenovo",
"module" : "Y410",
"serialNumber" : "123123",
"bardCode" : "21212",
"account" : 1212,
"usefulLife" : 24,
"downtimeCosts" : 200,
"purchasePrice" : 120000,
"assetState_id" : 1,
"assetCategory_id" : 3,
"assetSystem_id" : 3,
"supplier" : 1
};
request(url)
.post('/asset/create')
.send(asset)
.end(function(err, res) {
if (err) {
throw err;
}
console.log (res.should.have);
res.should.have.status(200);
done();
});
});
});
});
POST 작업은 다음과 같습니다.
router.post('/create', function(req, res, next) {
models.asset.create(req.body
).then(function(asset) {
res.send(asset.dataValues)
}).catch(function(error) {
console.log (error);
res.status(500).send(error);
});
});
테스트를 실행할 때 다음 오류 Uncaught TypeError: undefined is not a function
가 줄에 표시 됩니다. res.should.have.status(200);
이유는 상태 응답을 명시 적으로 말하지 않았기 때문에 res를`res.status (200) .send (asset.dataValues)로 변경했지만 작동하지 않기 때문입니다.
다음 코드를 시도해야한다고 생각합니다.
should(res).have.property('status', 200);
res에 ".should"속성이 없다는 사실을 해결합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다