"use strict" var app = require(’…/…/app’); var request = require(‘supertest’)(app); var mm = require(‘mm’); var mailService = require(’…/…/src/common/mail’); var UserProxy = require(’…/…/src/proxy/user’); var pedding = require(‘pedding’); var should = require(‘should’); describe(‘test/controllers/sign.test.js’, function(){ var now = +new Date(); var loginname = ‘testuser’ + now; var email = ‘testuser’ + now + ‘@gmail.com’; var pass = ‘wtffffffffffff’;
afterEach(function () {
mm.restore();
});
describe('sign up', function(){
it('should visit sign up page', function (done) {
request.get('/signup')
.expect(200, function (err, res) {
res.text.should.containEql('确认密码');
done(err)
});
});
it('should sign up a user', function (done) {
done = pedding(2, done);
mm(mailService, 'sendMail', function (data) {
data.to.should.match(new RegExp(loginname + '@gmail\\.com'));
done();
});
request.post('/signup')
.send({
loginname: loginname,
email: email,
pass: pass,
re_pass: pass,
})
.expect(200, function (err, res) {
should.not.exists(err);
res.text.should.containEql('欢迎加入');
UserProxy.getUserByLoginName(loginname, function (err, user) {
should.not.exists(err);
user.should.ok;
done();
});
});
});
基本是 nodeclud 的那个,但是在我的项目中
test/controllers/sign.test.js sign up GET /signup 200 163.238 ms - - ✓ should visit sign up page (173ms) POST /signup 403 29.443 ms - - 1) should sign up a user failing 1) test/controllers/sign.test.js sign up should sign up a user: Uncaught AssertionError: expected Error { message: ‘expected 200 “OK”, got 403 “Forbidden”’ } to not exist at Test.<anonymous> (test/controllers/sign.test.js:50:32) at Test.assert (node_modules/supertest/lib/test.js:156:6) at Server.assert (node_modules/supertest/lib/test.js:127:12) at emitCloseNT (net.js:1518:8)
启动项目是 正常的,请大神指导问题是在哪里?