function dictionaryResourceService(
ResourceExceptionHandler,
$resource,
$q,
) {
var dictionaryResource = this;
dictionaryResource.insertDictionary = insertDictionary;
function insertDictionary(dictionary) {
var defer = $q.defer();
dictionaryResource.resource.insert(dictionary, function () {
defer.resolve();
}, function (error) {
var resourceException = new ResourceExceptionHandler();
resourceException.setException(error);
resourceException.setExceptionMessage('insert_error');
defer.reject(resourceException);
});
return defer.promise;
}
}
DictionaryResource.service('DictionaryResource', [
'ResourceExceptionHandler',
'$resource',
'$q',
dictionaryResourceService
]);
function resourceExceptionHandlerService($q) {
return function () {
var resourceExceptionHandler = this;
resourceExceptionHandler.setException = setException;
resourceExceptionHandler.setExceptionMessage = setExceptionMessage;
};
}
Exception.service('ResourceExceptionHandler', [
'$q',
resourceExceptionHandlerService
]);
var dictionaryResource,
dictionaryStub,
$httpBackend;
beforeEach(function () {
module('Exception', 'DictionaryResource');
});
beforeEach(function () {
dictionaryStub = jasmine.createSpyObj('Dictionary', [
'isNew',
'getDictionary'
]);
});
beforeEach(inject(function (_DictionaryResource_, _$httpBackend_) {
dictionaryResource = _DictionaryResource_;
$httpBackend = _$httpBackend_;
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('Method: insertDictionary', function () {
it('Should return a ResourceExceptionHandler when Rest server throws error', function () {
var dictionary = dictionaryResource.insertDictionary(dictionaryStub);
expect(dictionary.then).toBeDefined();
$httpBackend.expect('POST', 'api/dictionaries').respond(500, {
reject: true
});
$httpBackend.flush();
expect(dictionaryStub.isNew).toHaveBeenCalled();
expect(dictionaryStub.getDictionary).toHaveBeenCalled();
dictionary.then(null, function (error) {
});
});
});
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.
beforeEach(inject(function (_DictionaryResource_, _ResourceExceptionHandler_, _$httpBackend_) {
dictionaryResource = _DictionaryResource_;
resourceExceptionHandler = new _ResourceExceptionHandler_;
$httpBackend = _$httpBackend_;
}));
spyOn(resourceExceptionHandler, 'setException');
dictionary.then(null, function (error) {
expect(resourceExceptionHandler.setException).toHaveBeenCalled();
});
Expected spy setException to have been called.
spyOn(resourceExceptionHandler.prototype, 'setException');
Error: spyOn could not find an object to spy upon for setException()