Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing AngularJS directive with templateUrl
    primarykey
    data
    text
    <p>I have an AngularJS directive that has a <code>templateUrl</code> defined. I am trying to unit test it with Jasmine.</p> <p>My Jasmine JavaScript looks like the following, per the recommendation of <a href="https://stackoverflow.com/questions/14761045/jasmine-tests-angularjs-directives-with-templateurl">this</a>:</p> <pre><code>describe('module: my.module', function () { beforeEach(module('my.module')); describe('my-directive directive', function () { var scope, $compile; beforeEach(inject(function (_$rootScope_, _$compile_, $injector) { scope = _$rootScope_; $compile = _$compile_; $httpBackend = $injector.get('$httpBackend'); $httpBackend.whenGET('path/to/template.html').passThrough(); })); describe('test', function () { var element; beforeEach(function () { element = $compile( '&lt;my-directive&gt;&lt;/my-directive&gt;')(scope); angular.element(document.body).append(element); }); afterEach(function () { element.remove(); }); it('test', function () { expect(element.html()).toBe('asdf'); }); }); }); }); </code></pre> <p>When I run this in my Jasmine spec error I get the following error:</p> <pre><code>TypeError: Object #&lt;Object&gt; has no method 'passThrough' </code></pre> <p>All I want is for the templateUrl to be loaded as is - I don't want to use <code>respond</code>. I believe this may be related to it using <a href="http://docs.angularjs.org/api/ngMock.$httpBackend" rel="noreferrer">ngMock</a> instead of <a href="http://docs.angularjs.org/api/ngMockE2E.$httpBackend" rel="noreferrer">ngMockE2E</a>. If this is the culprit, how do I use the latter instead of the former?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload