Currently, I am attempting to utilize Jasmine to test if my array (storage) has gained an additional item. Despite having multiple promise chains, I am unable to access the first one as nothing seems to occur within the promise (.then).
Below is my test :
beforeEach(inject(function ($state, $controller, $rootScope, $q) {
state = $state.get('app.provision_requests_create');
ctrl = $controller('ProvisionRequestsCreateCtrl', {
$scope: $rootScope.$new(),
provider: {
data: {
priceStorage: function () {
return $q(function (resolve) {
resolve({ data: [] });
});
}
}
}
});
}));
describe("should test add Volume", function() {
it('should remove volume properly ', function () {
ctrl.createVolume(volume);
ctrl.provider.priceStorage().then(function(){
console.log('ok');
});
});
This is my function :
_this.provider = provider.data;
_this.instance.additional_values.storage = [];
_this.createVolume = function (volume) {
var newvol = angular.copy(volume);
//reset input and select
angular.copy({},volume);
return _this.provider.priceStorage(newvol.kind).then(function (resp) {
...
return _this.provider.priceSnapshot();
})
.then(function (resp) {
_this.instance.additional_values.storage.push(newvol);
});
};
When I log ctrl.provider.priceStorage(), the output is as follows:
d{$$state: Object{status: 1, value: Object{data: ...}}}
Upon logging ctrl.createVolume(), the result obtained is:
d{$$state: Object{status: 0}}