我想用Karma和Jasmine测试我的基于AngularJS和TypeScript的应用程序。
我的编辑ArticleComment
:
$query = $queryBuilder->getQuery();
$query->getResult(Query:HYDRATE_ARRAY);
我的controllerSpecs.ts
:
/// <reference path="../references.ts" />
describe('ConfigCtrl', () => {
var configCtrl, scope;
beforeEach(angular.mock.module('typewritingApp'));
beforeEach(angular.mock.inject(($rootScope) => {
scope = $rootScope.$new();
configCtrl = new App.TestCtrl(scope);
}));
it('should be true', () => {
expect(true).toBe(true);
});
});
我的app.ts
:
module App {
import TypewritingCtrl = App.TypewritingCtrl;
import MenuCtrl = App.MenuCtrl;
var typescrip: ng.IModule;
var typewritingapp: ng.IModule = angular.module("typewritingApp", ["ngRoute", "ui.bootstrap", "LocalStorageModule", "ui.event", "timer"])
.controller("TestCtrl", ["$scope", TestCtrl])
}
当我试图运行测试时,业力给我写的错误:
TestController.ts
如果我从代码中删除了注入部分,它会成功运行并且测试通过。任何人都可以帮助我,我做错了什么?
答案 0 :(得分:0)
我们应该要求将服务 $rootScope
作为本地$scope
生成器:
// beforeEach(angular.mock.inject(($scope) => {
beforeEach(angular.mock.inject(($rootScope) =>
{
// HERE we do create a $scope from $rootScope
scope = $rootScope.$new();
configCtrl = new App.TestCtrl(scope);
}));