我正在尝试使用 npm replay 包在集成测试时记录 http 响应。我正在使用柴和摩卡。这是我的代码:
var chai = require('chai');
var bodyParser = require('body-parser');
var supertest = require('supertest');
var express = require('express');
var expect = chai.expect;
var replay = require('replay');
var assert = require('assert');
var HTTP = require('http');
var primary = require('./data/primary.json');
describe('Server Tests', function() {
beforeEach(function(){
replay.localhost('127.0.0.1:3978');
});
it('should run the replay module', function(done) {
supertest('http://localhost:3978')
.post('/api/messages')
.send(primary)
.end(function (err, response) {
console.log(response);
expect(response.statusCode).to.eq(202);
//expect(response.body).to.eq("Oxymoron 2. Exact estimate\n\n[codehappy] http://iheartquotes.com/fortune/show/38021\n");
console.log('Woot!');
done();
});
});
});
另外,我得到了正确的响应状态代码。