- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下关于 Controller 的规范。我有以下 Jasmine 规范:
describe 'MyApp.Controller.SomeController', ->
beforeEach module('mymodule')
beforeEach inject ($rootScope , $httpBackend, $controller, SomeService) ->
@scope = $rootScope.$new()
@httpBackend = $httpBackend
someService = SomeService
@someResource = someService.someResource
$controller 'MyApp.Controller.SomeController', $scope: @scope
describe "#fetchMethod", ->
describe "given an object", ->
beforeEach ->
@id = 17
@scope.fetchMethod(@id)
it "sets due to true", ->
@httpBackend.whenGET().respond(200, {"someStrings": ["foo", "bar"], otherStrings: ["bar", "goo"]})
expect(@scope.someStrings).toBeDefined()
expect(@scope.otherStrings).toBeDefined()
环绕以下 Controller :
MyApp.Controller.SomeController = (scope, someService) ->
scope.fetchMethod = (ID)->
someService.someResource.fetch
Id: artID
,(response) ->
scope.someStrings = response['someStrings']
scope.otherStrings = response['otherStrings']
scope.someStringsExist = true if scope.someStrings
MyApp.Controller.SomeController.$inject = ['$scope', 'SomeService']
其中 SomeService 定义如下:
MyApp.Service.SomeService = (resource) ->
@someResource = resource '/api/foos/:ID', {},
fetch:
method: 'GET'
@
MyApp.myModule.service 'SomeService', ['$resource', MyApp.Service.SomeService]
此设置似乎在站点上运行,正确执行请求并从 (rails) api 端点返回值。
但是,当 jasmine 规范运行时,它失败了:
错误:意外请求:GET/api/foos/17 在 http://localhost:3000/assets/helpers/angular-mocks.js?body=1(第 889 行)中预计不再有请求
我错过了什么?为什么 httpBackend 无法识别 GET 请求?
scope.initialize = (artifactId, artifactType)-> 范围.artifactId = artifactId scope.artifactType = 工件类型 scope.currentVersionExists = false 作用域.attachmentFetcher(scope.artifactId)
MyApp.Controller.SomeController.$inject = ['$scope', 'SomeService']
最佳答案
在发出请求之前,您应该在响应中添加 stub 的这一行:
@httpBackend.whenGET().respond(200, {"someStrings": ["foo", "bar"], otherStrings: ["bar", "goo"]})
关于http - ngMock 无法识别请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15209979/
我的 ng 应用程序工作正常,但我正在尝试为我的 Controller 编写 ngMock 测试;我基本上是按照 Angular 网站上的示例进行操作的:https://docs.angularjs.
我有以下关于 Controller 的规范。我有以下 Jasmine 规范: describe 'MyApp.Controller.SomeController', -> beforeEach
有没有办法使用 angular-mocks.js 调用无后端请求模拟,测试外部站点?在代码库上有很多使用 Angular 模拟的示例,开发人员可以添加 .然而,我陷入了一个场景......在野外调用
我在 GET/#/car/view/0 上收到意外请求错误,其中 0 是 :carId。 它用于 ngMock 后端上的基本 Angular crud 应用程序。 $httpBackend.whenG
情况: 我需要安装angular-mocks在我的 Ionic 应用程序中,但完成后,应用程序崩溃了。就在依赖项中注入(inject)“ngMock”之后。通过删除它,应用程序可以正常工作。 然后我尝
我正在将 Angular 应用程序的所有 Protractor E2E 测试切换为 ngMock ,这样我们就可以模拟我们的资源/http 调用。但是,我找不到推荐的加载方法ngMock在那种情况下。
场景 我目前正在为一个 Angular 项目编写测试,几乎在我找到的每篇文章中,我都看到他们在 describe block 中创建 “全局” 变量,其中它们存储要在测试中使用的依赖项,如下所示: d
我正在努力思考 Typescript、AngularJS 和 ngMock 部分。我见过像这样在单元测试开始时注入(inject)模块的代码。 beforeEach(angular.mock.modu
我正在尝试对外部 promise 的解决/拒绝进行单元测试。 问题是当注入(inject) ngMock 模块时,这些 promise 永远不会完成 - 这是强制性的,因为我正在触发 HTTP 请求和
我没有 ngMock 的代码是 'here' . var app = angular.module('logExample',[]); app.controller('LogController',
我在使用 ngMocks 和其中模拟的 $log 提供程序时遇到问题。 任何时候在我的代码中使用 $log,测试都会失败,因为 $log 的 mock 在(第 295 行)失败: var $log =
我已经看了好几个小时了。我试过一个又一个例子。我似乎无法让它发挥作用。请帮忙=) 我在 angular-seed repo (git://github.com/angular/angular-seed
给定以下服务: angular.module('app', []) .service('promisey', function ($q) { this.cakey = function (
有代码: angular.module('myApp', ['ngMock']); 加载 ngMock 时出现此类错误。未捕获的类型错误:$$rAF.throttle 不是函数 最佳答案 问题似乎来自
我是一名优秀的程序员,十分优秀!