我不知道我笨,但是,我已经安装了网络请求模块:进口所有打字稿不起作用
npm install web-request
它被安装,它存在于节点模块。 我尝试使用它:
import * as WebRequest from 'web-request';
export class MyHttp {
public static getUrl() {
console.log('hello');
WebRequest.get('http://www.google.com/').then(()=> {
console.log('success');
});
}
}
然后,我用它在测试:
import {MyHttp} from '../../../services/MyHttp';
describe('Request',() => {
fit('should be successful',() => {
MyHttp.getUrl();
setTimeout(()=> {
expect(true).toBe(true);
},5000);
});
});
控制台输出为:
hello
我无法看到 '成功' 输出在所有。
打字没问题,我可以输入web-request \ index.d.ts,看起来很好。
我在做什么错? :(
您的测试运行器正在退出,因为它不知道您正在运行异步行为。阅读茉莉花文档以了解如何编写异步测试功能。 –
不要创建只包含静态方法的类,也不要导出它们:http://stackoverflow.com/q/29893591/1048572 – Bergi
您是否曾尝试在承诺中添加“catch”错误处理程序? – Bergi