Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 在ember qunit中模拟HTTP请求_Ember.js_Mocking_Qunit_Ember Cli - Fatal编程技术网

Ember.js 在ember qunit中模拟HTTP请求

Ember.js 在ember qunit中模拟HTTP请求,ember.js,mocking,qunit,ember-cli,Ember.js,Mocking,Qunit,Ember Cli,在ember cli应用程序中,使用ember qunit完成测试 我想模拟HTTP请求,但还没有找到推荐的方法 我已经讨论过这一点,但它似乎已经过时了(无论如何,对于ember cli) 如何模拟HTTP请求?这就是我模拟HTTP请求的方式。一个改进可以通过使用类似以下帮助器的方法封装mockjax: function stubEndpointForHttpRequest(url, json) { $.mockjax({ url: url, dataTy

在ember cli应用程序中,使用ember qunit完成测试

我想模拟HTTP请求,但还没有找到推荐的方法

我已经讨论过这一点,但它似乎已经过时了(无论如何,对于ember cli)


如何模拟HTTP请求?

这就是我模拟HTTP请求的方式。一个改进可以通过使用类似以下帮助器的方法封装
mockjax

function stubEndpointForHttpRequest(url, json) {
    $.mockjax({
        url: url,
        dataType: 'json',
        responseText: json
    });
}
因此,您可以轻松地切换到另一个库,如
sinon
或其他任何库

module('Integration - Signin Tests', {
    setup: function(){
        App = startApp();
    },
    teardown: function(){
        Ember.run(App, 'destroy');
        $.mockjaxClear(); // Don't forget to clear mockjax
    }
});

test('Signin with valid data', function(){
  expect(2);

  stubEndpointForHttpRequest('api_url', 'response_json');

  // Write your test
});

我希望这有助于检查。谢谢你的回答。我遇到了几个绊脚石,其他人可能会发现这些绊脚石很有用:(1)mockjax不支持跨域API请求,让我们通过它们。如果你的应用程序是这样,请在测试中更改它们。(2) Mockjax不需要集成测试-单元测试也可以工作
startApp
App.destroy