您好,我正在使用Mocha进行单元测试,一切正常,直到使用io.emit
测试方法为止,您可以在下面看到我的代码:
var emit = (type, to, content, url) => {
var f = false;
var io = require("../index").io;
var socketIds = global.socketIds;
if (socketIds && socketIds[to]) {
let sockets = socketIds[to];
for(let item of sockets){
io.to(item).emit(type, { type: type, content: content, url: url });
f = true;
}
}
return f;
};
这是我的测试代码:
describe("create new notification with offline account", () => {
it("it should be return a notification and offline status", done => {
const save = global.socketIds;
global.socketIds = {};
callService(expected.notification, result => {
Notification.findOne(expected.notification, (err, noti) => {
expect(result.online).to.equal(expected.online);
expect(noti).to.exist;
global.socketIds = save;
done();
});
});
});
});
Mocha not finish and stop here