【发布时间】:2018-05-15 20:16:13
【问题描述】:
我是新手,无法让超测为我工作。我想知道:
- 为什么主体未定义?
- 命令行中是否有技巧可以在控制台中显示和检查对象?
- 为什么测试不记录“hello”?
"use strict";
const request = require('supertest');
const express = require('express');
const https = require('https');
const fs = require('fs');
const path = require('path');
const certPath = path.resolve(path.resolve(), './certs');
const app = express();
//This line is from the Node.js HTTPS documentation.
const options = {
key : fs.readFileSync(certPath+'/server-key.pem'),
cert : fs.readFileSync(certPath+'/server-crt.pem'),
ca : fs.readFileSync(certPath+'/ca-crt.pem')
};
// service
app.post('/failService', function(req, res) {
console.log('failService: '+req.body); // failService: undefined
res.send('hello');
});
describe('trial not working', function() {
it('responds with json', function(done) {
request(app)
.post('/failService')
.send({name: 'john'})
.set('Accept', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
console.log('response: '+res.body); // response: [object Object]
done();
});
});
});
....显示
$ mocha supertest.js
trial not working
failService: undefined
response: [object Object]
√ responds with json (125ms)
1 passing (171ms)
请注意,证书(不包括在内)是自签名的。
【问题讨论】:
标签: node.js express https supertest