I've encountered a problem while writing a unit test for my Angular application using Jasmine with a mock service. The promise I am trying to run is not functioning as expected.
Below is the service code:
CreateItemController = $controller('CreateItemController', {
ItemService: {
createItem: function(data) {
console.log('Service running');
var defer = $q.defer();
defer.resolve('1');
return defer.promise;
}
The test script looks like this:
it('should create an item', function() {
var created = false;
$scope.createItem().then(function(response) {
// This section is not executing
console.log("We got through");
created = true;
});
expect(created).toBe(true);
})
And here's the actual function implementation:
$scope.createItem = function() {
var postData = {
name: 'Jeans'
};
return ItemService.createItem(postData).then(function(response) {
// This part is also not running
console.log('Promise received');
});
}
Can anyone help me figure out what mistake I'm making?