expect - response在AngularJS单元测试(Jasmine)中不起作用
Expect-respond doesn't work in AngularJS unit testing(Jasmine)
我的目标是通过AngularJS mock服务(jasmine)的预设响应将数据加载到html中。数据。Json也在那里,所以如果模拟响应不起作用,显示的单词将是"http"而不是"mock"。但是响应结果总是"http",这意味着模拟服务并不真正工作。非常感谢你对这个问题的任何建议。
茉莉javascript文件:
describe("DController", function() {
var httpBackend,scope;
beforeEach(module('MyApp'));
beforeEach(inject(function($rootScope,$httpBackend,$http,$controller) {
scope = $rootScope.$new();
httpBackend = $httpBackend;
DController = $controller('DController', {
$scope: scope
});
httpBackend.expectGET('data.json').respond({
"name": "mock"
});
})); })
controller.js文件.controller('DController',function($scope,$http) {'use strict';
$scope.loadJson = function() {
var getDataJson = $http.get('data.json');
getDataJson.success(function(data, status, headers, config) {
$scope.data = data;
});
}})
和数据。Json就是
{ "name": "http" }
您是否尝试使用"whenGET"而不是"expectGET"?
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 使用$httpBackend测试Jasmine/Karma的AngularJS不起作用
- JavaScriptgetter的Jasmine测试不起作用
- 在Jasmine中,数组.Includes不起作用(必须用其他函数代替).为什么
- Protractor/Jasmine测试浏览器.isElementPresent在查找类时不起作用
- expect - response在AngularJS单元测试(Jasmine)中不起作用
- 即使抛出错误,Jasmine toThrow也不起作用
- 使用Jasmine jQuery,我试图更改fixture HTML,但它没有;不起作用
- Angular指令的Jasmine测试不起作用
- Jasmine mock ajax调用在IE中不起作用