使用AngularJS。
有一个指令。
指令定义templateUrl
。
指令需要单元测试。
目前使用Jasmine进行单元测试。
This推荐的代码如下:
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'
templateUrl需要按原样加载
无法使用respond
https://stackoverflow.com/questions/15214760
复制相似问题