关于业力单位测试的意外GET请求

时间:2016-08-18 22:22:18

标签: phantomjs karma-jasmine httpbackend angular-mock

我正在使用业力测试我的角度应用程序中的控制器,该应用程序自动按预期工作但单元测试抛出error: unexpected request: GET views/home.html 因为我遇到的问题是由ui-router和$ httpBackend。所以有一种方法是通过'karma-preprocessor'进行缓存,但我所做的是:

var MenuController, scope, $httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, _$httpBackend_, $rootScope, menuService) {
// place here mocked dependencies
$httpBackend = _$httpBackend_;
$httpBackend.whenGET("views/header.html").respond(200,'');
$httpBackend.expectGET("http://localhost:3000/dishes").respond([{ ....

但是我的views文件夹中的每个模板都显示了GET错误。

现在有没有办法忽略所有模板和任何其他意外的GET请求?

1 个答案:

答案 0 :(得分:1)

您可以创建与所有模板请求匹配的正则表达式: httpBackend.whenGET(/views\/.*\.html/).respond(200, {});或仅限httpBackend.whenGET(/views\//).respond(200, {}) Dim value Dim lRow Dim fieldvalue ReDim fieldvalueChar(1) ' Just Declare an array of 1, Since array size has to be constant when declaring 'Open the spreadsheet document for read-only access. Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Users\saravananp\Desktop\Items.xls") Set ws = objWorkbook.Sheets("Items") rowcount = ws.usedrange.rows.count ' Redefine array size dynamically based on number of Rows ReDim fieldvalueChar(rowcount) for j = 1 to rowcount fieldvalueChar(j-1) = ws.cells(j,1) next MsgBox(fieldvalueChar(0)) MsgBox(fieldvalueChar(1))