在这个测试中,我不确定为什么你需要将角度变量设置为这两行中的注入参数。是因为注入不会自动分配$ compile和$ rootScope吗?
$compile = $c;
$rootScope = $r;
这
describe("Unit: Testing Directives", function() {
var $compile, $rootScope;
beforeEach(module('App'));
beforeEach(inject(
['$compile','$rootScope', function($c, $r) {
$compile = $c;
$rootScope = $r;
}]
));
it("should display the welcome text properly", function() {
var element = $compile('<div data-app-welcome>User</div>')($rootScope);
expect(element.html()).to.match(/Welcome/i);
})
});
答案 0 :(得分:1)
尝试这样的事情对我有用:
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
$scope = $rootScope.$new();
$http = $injector.get('$http');
$q = $injector.get('$q');
}));