I am rather new to angular and testing in general. I am trying to set up a basic test where I see if the object is defined before I start trying to test anything else.
I am getting this error:
Error: [$injector:unpr] Unknown provider: $stateParamsProvider <- $stateParams <- Form
However when I try and do this basic test on other test files this error does not show up.
Factory
angular.module('omnibyte_inspect_web.objects')
.factory('CommonQuestions', ['common_questions_factory', 'Form', '$rootScope',
function (common_questions_factory, Form, $rootScope) {
// Ctor
function CommonQuestions(data) {
var keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
this[keys[i]] = data[keys[i]];
}
};
CommonQuestions.prototype.Select = function () {
this.Id = guid();
Form.CurrentForm().AddCommonQuestion(angular.copy(this));
};
CommonQuestions.prototype.Remove = function () {
common_questions_factory.delete(this.Id).then(function () {
window.location.reload();
});
};
// Static Methods
CommonQuestions.Current = function () {
return $rootScope.config_info;
};
CommonQuestions.GetAll = function (callback) {
common_questions_factory.get().then(function (data) {
var collection = [];
for (var i = 0; i < data.length; i++) {
collection.push(new CommonQuestions(data[i]));
}
callback(collection);
});
};
return CommonQuestions;
}]);
Test File
describe('CommonQuestions Test', function () {
beforeEach(module('omnibyte_inspect_web.objects'));
var common_questions_factory, $rootScope, CommonQuestions, Form;
beforeEach(inject(function (_common_questions_factory_, _Form_, _$rootScope_, _CommonQuestions_) {
common_questions_factory = _common_questions_factory_;
Form = _Form_;
$rootScope = _$rootScope_;
CommonQuestions = _CommonQuestions_;
spyOn(CommonQuestions, 'GetAll');
spyOn(common_questions_factory, 'get');
spyOn(CommonQuestions, 'Current');
}));
it('should have CommonQuestions be defined', function () {
expect(CommonQuestions).toBeDefined();
});
});
Aucun commentaire:
Enregistrer un commentaire