以下测试表现得很奇怪:
it('Should return the exchange rates for btc_ltc', function(done) {
var pair = 'btc_ltc';
shapeshift.getRate(pair)
.then(function(data){
expect(data.pair).to.equal(pair);
expect(data.rate).to.have.length(400);
done();
})
.catch(function(err){
//this should really be `.catch` for a failed request, but
//instead it looks like chai is picking this up when a test fails
done(err);
})
});
Run Code Online (Sandbox Code Playgroud)
我该如何妥善处理被拒绝的承诺(并对其进行测试)?
我该如何正确处理失败的测试(即:expect(data.rate).to.have.length(400);?
这是我正在测试的实现:
var requestp = require('request-promise');
var shapeshift = module.exports = {};
var url = 'http://shapeshift.io';
shapeshift.getRate = function(pair){
return requestp({
url: url + '/rate/' + pair,
json: true
}); …Run Code Online (Sandbox Code Playgroud) 我想编写一些代码,只有在全局安装软件包时才会在npm postinstall上执行.是否有内置的解决方案来检测活动包是否全局安装?
如果没有那么什么是适用于任何操作系统的最佳解决方案?我目前唯一的想法是检查包的当前工作目录,并检查它是否在全局npm路径下.
我的项目中有一个AspxGridView AllowFocusedRow="True".每次加载页面(带表格)时,第一行都会被聚焦.当我在服务器端(在页面加载之前)为gvMain.FocusedRowIndex分配-1时,它没有帮助.但是当我在客户端更改焦点行索引时:
Init="function() {
gvMain.SetFocusedRowIndex(-1);
Run Code Online (Sandbox Code Playgroud)
然后它加载表格,选择第一行,然后消失.所以我想最好先定义一下.但是怎么样?
我有一个返回网页内容的方法:
private string FetchHTML(string sUrl, Encoding encoding)
{
System.Net.WebClient oClient = new System.Net.WebClient();
oClient.Encoding = encoding;
return System.Web.HttpUtility.HtmlDecode(oClient.DownloadString(sUrl));
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试从livejournal加载链接时(例如,http: //mos-jkh.livejournal.com/769579.html ),我在DownloadString上收到此异常:
请求已中止:操作已超时.
这是一个已知的问题吗?为什么DownloadString不适用于某些网页,是否有解决方案?或者有替代DownloadString?
asp.net ×2
node.js ×2
aspxgridview ×1
c# ×1
chai ×1
devexpress ×1
mocha.js ×1
npm ×1
promise ×1