I've got an angular app going with some jasmine testing. I recently added a new method to make a query to elastic search within one of my services, it looks like this.
test:
function(){
return "Working";
},
executeSearch:
function(field, value, size, page_number){
return service.executeRegExSearch(field, value, size, page_number);
},
//new method
executeRegExSearch:
function(field, value, size, page_number){
//main search body, I know it works because
//I am getting expected results in the browser
}
And then in my jasmine tests, I've got something like this.
//initialization stuff
var $httpBackend;
var searchAPI;
beforeEach(inject(function($injector){
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
$httpBackend = $injector.get('$httpBackend');
searchAPI = $injector.get('searchAPI');
}));
it("is loaded properly", function(){
expect(searchAPI.test() == "Working").toBe(true); //passes
});
it("can make a request", function(){
var field = "col_name";
var value = "bb.*"; //this is matching in my browser/application
var size = 10;
var page_number = 1;
var res;
searchAPI.executeSearch(field, value, size, page_number).then(function(res){
res = res;
alert(JSON.stringify(res));
done();
});
$httpBackend.flush();
});
But when I run, I get the error
Unexpected request: GET http://myserver/index-1/_search?source={"query":{"regexp":{"col_name":{"value":"bb.*"}}}}"&size=10&from=0 No more request expected in http://localhost:8081/js/angularjs/angular-mocks.js (line 1180)
I'm not sure about how to use the mocks, or am even aware that I was doing it. All I want to do is be able to run a suite of tests that make actual calls to my backend to confirm that things are being integrated properly... you know.. integration tests.
Anyone have any advice?