Open unclejustin opened 10 years ago
This generator uses grunt-angular-templates.
The error you're getting sounds like you haven't configured the htmlBackend to correctly pass through requests for templates. You shouldn't need to preload templates for unit tests.
Sent from my iPhone
On Nov 3, 2014, at 10:26 AM, unclejustin notifications@github.com wrote:
Ran into this while trying to build and test a simple directive. I fixed it using ng-html2js. (more info here: http://stackoverflow.com/questions/26682740/ng-html2js-doesnt-work-with-phantom-does-work-with-chrome).
Shouldn't ng-html2js be included in this generator? Has no one else run into this same problem?
— Reply to this email directly or view it on GitHub.
I'm definitely doing something wrong. I tried setting up passthrough but could not get it to work. html2js is working for me currently, but I would love to work within the framework provided.
Here is what I tried that did not work for me:
beforeEach(function() {
module('BootstrapPlayground');
module('ngMockE2E');
inject(function(_$httpBackend_) {
var $httpBackend = _$httpBackend_;
$httpBackend.whenGET('directive/configData/configData.html').passThrough();
});
});
Closing this out since support requests shouldn't be in the issue queue.
I finally got this working. In the karma's options it was not including the ngtemplate file. I had to add "'<%= ngtemplates.main.dest %>'" to karma:options:files. That fixed me up.
Reopening this to see if '<%= ngtemplates.main.dest %>' is supposed to be included in the Gruntfile template.
I'm having the same problem here. My directives has a external template and the unit test fail to request it. Could someone share some code example how we suppose to do it?
You can use the nghtml2js preprocessor that @unclejustin mentions.
I'm using nghtml2js and is working, but a little different aproach:
directive example:
beforeEach(module('directive/email-widget/email-widget.html'));
my karma on grunt:
karma: {
options: {
frameworks: ['jasmine'],
preprocessors: {
'directive/**/*.html': ['ng-html2js']
},
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.appjs %>',
'bower_components/angular-mocks/angular-mocks.js',
'directive/**/*.html',
createFolderGlobs('*-spec.js')
],
logLevel:'ERROR',
reporters:['mocha'],
autoWatch: false, //watching is handled by grunt-contrib-watch
singleRun: true
},
all_tests: {
browsers: ['PhantomJS','Chrome','Firefox']
},
during_watch: {
browsers: ['PhantomJS']
},
}
Thank you for your help.
That looks right. Thats typically how you use nghtml2js. Though I usually stick all the templates in one module.
Hey Scoup, I got this working without ng-html2js. Check out my grunt file for reference: https://github.com/unclejustin/BootstrapPlayground/blob/master/Gruntfile.js
I had to add the files during the watch and in the karma options.
karma:options:files
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.appjs %>',
'<%= ngtemplates.main.dest %>',
'bower_components/angular-mocks/angulsar-mocks.js',
'directive/**/*.html',
createFolderGlobs(['*-spec.js'])
]
grunt.event.on var files = [].concat(grunt.config('dom_munger.data.appjs'), grunt.config('ngtemplates.main.dest'));
register task: grunt.registerTask('serve', ['dom_munger:read', 'sass', 'jshint', 'ngtemplates', 'concat', 'connect', 'watch']);
Hope that helps.
Thank you, unclejustin. That is what I was looking for, I'll try it later.
@unclejustin 's Gruntfile edits posted Dec, 1, '14 solved it for me as well. Is there any chance of a PR for that? It seems like a significant oversight for directive templates not to be included in the default Grunt setup.
Ran into this while trying to build and test a simple directive. I fixed it using ng-html2js. (more info here: http://stackoverflow.com/questions/26682740/ng-html2js-doesnt-work-with-phantom-does-work-with-chrome).
Shouldn't ng-html2js be included in this generator? Has no one else run into this same problem?