有没有人有一个例子 $httpBackend /service in module ngMockE2E /

我真的正在寻找最简单的制作申请的方法 angular 使用后端服务布局。

任何指针都会很棒,一个示例应用程序,显示如何编写一个简单的应用程序,使用它将执行此作业。 TPH!
已邀请:

江南孤鹜

赞同来自:

这里
http://plnkr.co/edit/QYKAKvqO9 ... eview
, 过多的 $httpBackend 对于具有后端的示例较少开发的开发作为答案的示例
https://coderoad.ru/14973602/
.

我加入的主要事情 plnkr, 让它工作, - 这是:

是指文件。
angular-mocks.js

在文件中 html.

添加
ngMockE2E

在阵列中 angular.module requires 排队 3 在 app.js

介绍
$httpBackend

在 app.run 并添加了向Mackenet后端报告的代码,该后端在请求时负责 GET 在混凝土上 URL.

它主要取自文件 $httpBackend. 注意你可以做到
.passThrough//

对于您真正想要以后的任何挑战 /绕过布局/. 如果后端部件已经工作,这尤其有用。

董宝中

赞同来自:

以下是从各种示例中获取的基本模板:


'use strict';

/function// {

if/ !document.URL.match//\?nobackend$// /{
// if not requested only add a blank stub to app dependency.
angular.module/'ds.backendMock', []/;

} else if /document.URL.match//\?nobackend$/// {

// if the query string is present add a module with a run definition to replace the back end.
angular.module/'myMock', ['ngMockE2E']/

.run/function/$httpBackend/ {

// MOCK-RUNNER-CONFIGURATION-.
var DOMAIN = 'example.com',
$httpBackend.whenGET/'http://'+DOMAIN+'/someexample'/
.respond/
//MOCK-ERROR-STATUS-CODE
//401 //500 //404 //uncomment integer to mock status code and comment out mock data.
//MOCK-DATA-RESPONSE
{
'id' : '1',
'name' : 'MOCK',
'description' : 'mocking',

}
/; //end mock.


// various passthroughs. these allow existing services to work, while some are mocked.
$httpBackend.whenGET/'./some.html'/.passThrough//;

// dont mock everything else, specify pass through to avoid error.
$httpBackend.whenGET//^\w+.*//.passThrough//;
$httpBackend.whenPOST//^\w+.*//.passThrough//;

}/;

}

}//angular/;

要回复问题请先登录注册