lundi 6 avril 2015

AngularJs unit test: "Unsatisfied requests: DELETE"

Getting "Unsatisfied requests: DELETE" for my controller test. below are the code for my service, controller and test. tests are written using jasmine-karma and angular-mock. Thanks in advance.


service:



function deleteAsset(assetId) {
return $http.delete(baseUrl + '/delete/' + assetId).then(assetDeleted);

function assetDeleted(response) {
return response.data;
}
}


Controller:



(function () {
'use strict';

angular.module('tbApp').controller('assetEditCtrl', assetEditCtrl);


assetEditCtrl.inject = ['$routeParams', 'Campaign', 'User', '$location', 'Asset', '$window', '$scope', '$compile', 'ImageLibrary', 'Lists'];

function assetEditCtrl($routeParams, Asset, $window, $scope, $compile) {

function deleteAsset(assetId,assetType,assetName, el) {
//confirmation popup
CB.setProceedBoxCode("Are you sure you want to delete "+assetType+" "+assetName+"?", el, {OK: "Yes", CANCEL: "No", width: "400", title: "", callback: function (r, ele) {

if (r == true) {

Asset.deleteAsset(assetId).then(assetDeleted);
}

}});


function assetDeleted(data) {

backTodashbiard();
}
} } });


Test:



describe('assetEditCtrl', function() {
var scope, httpBackend, http, controller, vm, createController, assetId, el, assetType, assetName, compile;

var baseUrl = './webresources/assets';

beforeEach(module("tbApp"));
beforeEach(inject(function($rootScope, $httpBackend, $controller, $http, $compile) {
httpBackend = $httpBackend;
compile = $compile
scope = $rootScope.$new();
controller = $controller;
assetId= "EML1000006003";
campaignId="CMP1000004385";

createController = function() {
var controller = $controller('assetEditCtrl', {
'$scope': scope
});


return controller;
};
}));

afterEach(function() {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
})

it('should be able to delete an asset', function(){

vm=createController();

assetType="email";
assetName="Untitled";

httpBackend.expectDELETE(baseUrl+'/delete/'+assetId).respond({});
vm.deleteAsset(assetId,assetType,assetName, el);
httpBackend.flush();

});});


Output:



Error: Unsatisfied requests: DELETE ./webresources/assets/delete/EML1000006003 in D:/Tb_test/src/main/webapp/js/libraries/uncompressed/angular-mocks.js
createHttpBackendMock/$httpBackend.verifyNoOutstandingExpectation@D:/Tb_test/src/main/webapp/js/libraries/uncompressed/angular-mocks.js:1488:7
createHttpBackendMock/$httpBackend.flush@D:/Tb_test/src/main/webapp/js/libraries/uncompressed/angular-mocks.js:1467:5
@D:/Tb_test/src/test/js/assetEditCtrlSpec.js:164:3
env.executeFiltered@D:/Tb_test/node_modules/karma-jasmine/lib/boot.js:117:7
createStartFn/<@D:/Tb_test/node_modules/karma-jasmine/lib/adapter.js:171:5
[2]</Karma/this.loaded@http://localhost:9876/karma.js:185:7

Aucun commentaire:

Enregistrer un commentaire