需要模块测试封面的帮助。 如何测试ws消息ok == true ||假?
我有下一个fnx:
this.WhenAnyValue(x => x.ViewModel.IssueSearchQuery)
.Throttle(TimeSpan.FromMilliseconds(1000), RxApp.MainThreadScheduler)
.DistinctUntilChanged()
.Do(_ =>
{
this.IssueAdapter.Issues.Clear();
})
.Select(searchTerm =>
{
if (SearchingProgressDialog == null && Activity != null)
{
ShowLoadingProgress();
}
var result = this.ViewModel.GetFilteredIssuesInProject(searchTerm);
return result
.ToObservable()
.ObserveOn(RxApp.MainThreadScheduler);
})
.Switch()
.Subscribe(searchResult =>
{
this.IssueAdapter.Issues.AddRange(searchResult);
this.IssueAdapter.NotifyDataSetChanged();
if (SearchingProgressDialog != null)
{
SearchingProgressDialog.Dismiss();
SearchingProgressDialog = null;
}
});
getItems.js
wss.on('connection', function (ws) {
ws.on('message', function (msg) {
getItems(ws, db);
});
});
这是我到目前为止所做的:
module.exports.getitems = function (ws, db) {
try {
var resData = new Object();
resData.ok = true;
db.collection('items').find({}).toArray(function (err, docs) {
if (err) {
ws.send({'ok': false});
} else {
ws.send(JSON.stringify({'ok':true}));
}
});
}
catch (e) {
console.error(e);
ws.send(JSON.stringify({'ok': false}));
}
};
});
我是测试的新手,所以不确定是否有可能测试这样的模块? 提前谢谢。