generator-cg-angular icon indicating copy to clipboard operation
generator-cg-angular copied to clipboard

Error: Unexpected request:

Open unclejustin opened this issue 9 years ago • 12 comments

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?

unclejustin avatar Nov 03 '14 15:11 unclejustin

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 [email protected] 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.

cgross avatar Nov 03 '14 16:11 cgross

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();
    });
});

unclejustin avatar Nov 03 '14 17:11 unclejustin

Closing this out since support requests shouldn't be in the issue queue.

unclejustin avatar Nov 04 '14 02:11 unclejustin

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.

unclejustin avatar Nov 14 '14 21:11 unclejustin

Reopening this to see if '<%= ngtemplates.main.dest %>' is supposed to be included in the Gruntfile template.

unclejustin avatar Nov 14 '14 21:11 unclejustin

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?

Scoup avatar Nov 27 '14 19:11 Scoup

You can use the nghtml2js preprocessor that @unclejustin mentions.

cgross avatar Nov 28 '14 17:11 cgross

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.

Scoup avatar Nov 28 '14 22:11 Scoup

That looks right. Thats typically how you use nghtml2js. Though I usually stick all the templates in one module.

cgross avatar Nov 28 '14 23:11 cgross

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.

unclejustin avatar Dec 01 '14 16:12 unclejustin

Thank you, unclejustin. That is what I was looking for, I'll try it later.

Scoup avatar Dec 01 '14 21:12 Scoup

@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.

ollwenjones avatar Jun 02 '15 19:06 ollwenjones