我有一个templateUrl定义的AngularJS指令.我正在尝试用Jasmine进行单元测试.
根据以下建议,我的Jasmine JavaScript如下所示:
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(
'<my-directive></my-directive>')(scope);
angular.element(document.body).append(element);
});
afterEach(function () {
element.remove();
});
it('test', function () {
expect(element.html()).toBe('asdf');
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
当我在我的Jasmine规范错误中运行它时,我收到以下错误:
TypeError: Object #<Object> has no method 'passThrough'
Run Code Online (Sandbox Code Playgroud)
我想要的是模板加载原型 - 我不想使用respond.我相信这可能与使用ngMock …