Git Product home page Git Product logo

Comments (6)

pkozlowski-opensource avatar pkozlowski-opensource commented on June 2, 2024

@spenoir the tab directive from this repo is using templateUrl:
https://github.com/vojtajina/ng-directive-testing/blob/master/js/tabs.js#L26

You can also find more complex examples in this repo prepared by Igor Minar and myself:
https://github.com/IgorMinar/directives-workshop

Unless you've got more specific questions....

from ng-directive-testing.

spenoir avatar spenoir commented on June 2, 2024

Thanks for the links.
I guess I'm talking about loading fixtures in really. When I test a directive that uses a template file I get unexpected GET errors for the template. I can fix this by using jasmine-jquery.getFixtures() and manually adding the response to the templateCache, but I can't see any other more simple way of loading html into a test.

from ng-directive-testing.

pkozlowski-opensource avatar pkozlowski-opensource commented on June 2, 2024

@spenoir I'm a bit confused.... If you put all the templates into $templateCache as pointed out in the above links you shouldn't see any HTTP requests under unit tests. Which makes sense since you definitively don't want to trigger HTTP requests while unit testing as this would make them run slower.

Not sure what you mean by "loading fixtures" exactly, though...

from ng-directive-testing.

spenoir avatar spenoir commented on June 2, 2024

I'm using a templateUrl that is different to the physical disk location. Could that be causing my unexpected get request? I'm using your examples as closely as possible.

Loading fixtures means loading data into tests rather than hard coding, its fairly standard in django envs at least...

from ng-directive-testing.

vojtajina avatar vojtajina commented on June 2, 2024

@spenoir the whole point of this example is to show how to use ng-html2js preprocessor. The example does use templateUrl. It sounds like you need to change the preprocessor configuration (cacheIdFromPath, see https://github.com/karma-runner/karma-ng-html2js-preprocessor).

from ng-directive-testing.

AdityaJitu avatar AdityaJitu commented on June 2, 2024

@vojtajina Even I am getting this message. I am trying to load the template Url by following this example but I am getting unexpected 'GET' errors. Any idea where I could be missing.

In karma conf.js
I am loading the files as
files: [
'../app/libs/angular/angular.js',
'../app/libs/angular-mocks/angular-mocks.js',
'../app/js/controllers/*.js',

    '../app/js/directives/*.js',

    'karma-spec.js',
    '../app/templates/helloworld.html'
],

and configuring as
preprocessors: {
'../app/js/controllers/*.js':['coverage'],
'../app/templates/helloworld.html':'html2js'
},

  ngHtml2JsPreprocessor:{
  stripPrefix:'../app',
  moduleName: "my.templates"
},

And in the test case

loading the module as beforeEach(module('my.templates'));

from ng-directive-testing.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.