I encountered an issue while attempting to test an http request with a dynamic URL.
Within my service file, I have the following snippet:
Snippet from My Service File:
//other service codes..
//other service codes..
var id = $cookies.id;
return $http.get('/api/product/' + id + '/description')
//id is dynamic
Test File:
describe('test', function () {
beforeEach(module('myApp'));
var $httpBackend, testCtrl, scope;
beforeEach(inject(function (_$controller_, _$httpBackend_, _$rootScope_) {
scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
testCtrl = _$controller_('testCtrl', {
$scope: scope
});
}));
it('should check the request', function() {
$httpBackend.expectGET('/api/product/12345/description').respond({name:'test'});
$httpBackend.flush();
expect(scope.product).toBeDefined();
})
});
Issue Description:
Error: Unexpected request: GET /api/product/description
I am unsure how to resolve this error related to testing the dynamic URL. Any assistance would be greatly appreciated. Thank you!