单元测试AngularJS指令与templateUrl
我有一个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');
});
});
});});当我在我的Jasmine规范错误中运行它时,我收到以下错误:
TypeError: Object #<Object> has no method 'passThrough'
我想要的是模板加载原型 - 我不想使用respond。我相信这可能与使用ngMock而不是ngMockE2E有关。如果这是罪魁祸首,我该如何使用后者而不是前者呢?
提前致谢!
慕妹3242003
慕慕森
随时随地看视频慕课网APP
相关分类