1
我试图在websocket事件触发后测试数据被添加到我的数据库中。如何编写我的代码来测试websocket事件?
在我正在使用的应用程序中,已经有一个这样的工作示例。
it('some test name', function (done) {
this.timeout(12000)
var socket = io.connect('http://localhost:3000', {
'transports': [
'websocket',
'flashsocket',
'jsonp-polling',
'xhr-polling',
'htmlfile'
]
})
socket.emit('some-room-event', {
participant: 'p1',
room: 12,
active: true
})
setTimeout(function() {
app.service('rooms').get(12)
.then(function (room) {
assert(room.active === true)
socket.disconnect()
done()
}).catch(function (err) {
socket.disconnect()
done(err)
})
}, 11000)
})
我来自一个红宝石背景和插入项目,所以我很新。感觉有点像使用超时是一种代码味道,它只是感觉不对。您不想增加运行测试所需的时间,而且需要等待一段时间。
我已经阅读了很多文章,但它很混乱。有没有更好的方法来构建这个代码,并有可能摆脱setTimeout?
我正在使用feathersjs,摩卡和断言。
是的,我也觉得不对。当你在新空间时很难说服你。谢谢。 –
我不怀疑它。尽管如此,仍然不会让你错。希望来自框架作者之一的输入有助于支持你:) – Daff