I'm getting this error when I'm unit testing a directive. Instead to use httpBackEnd for retrieving the template. I' using ng-html2js on Karma config.
Error: Unexpected request: GET http://
My point is that when I'm rendering data-mylist directive I'm getting the error above because in the controller liked to this directive there's a service using an $http call on the loading of the directive.
Then I'm wondering. ng-html2js is being used just to load the template and then I have to use httpbackend to deal with this specific $http call.
Or
Should the ng-html2js already give me the template with all dynamic data rendered?
Unit test
ddescribe('Directive', function () {
// load the directive's module
beforeEach(module('App'));
beforeEach(module('Templates')); // The external template file referenced by templateUrl
var element, scope, _Dataservice_;
beforeEach(inject(function ($rootScope, Dataservice) {
scope = $rootScope.$new();
_Dataservice_ = Dataservice;
}));
it('Should show message for no data found', inject(function ($compile) {
spyOn(_Dataservice_, 'dataList').andReturn(null); //spy the dataList function
//_Dataservice_.dataList= null;
element = angular.element('<div data-mylist></div>');
element = $compile(element)(scope);
scope.$digest();
expect(element.find('mylistClass').length).toBe(1);
}));
});
Karma config(part of):
module.exports = function(config) {
config.set({
preprocessors: {
'app/src/**/views/**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
//stripPrefix: 'app/',
//or define a custom transform function
cacheIdFromPath: function(filepath) {
return filepath.match(/src\/.*\/views\/.*\.html/)[0];
},
// setting this option will create only a single module that contains templates
// from all the files, so you can load them all with module('foo')
moduleName: 'Templates'
},
});
};
Aucun commentaire:
Enregistrer un commentaire