1
引發異常茉莉
我面臨着一個奇怪的例外,同時測試我寫在這裏打字稿角的東西都被我的文件:AngularJs測試通過噶
文件名:routeStates.ts
module Application {
'use strict';
class RootState implements ng.ui.IState {
name: string;
url: string;
template: string;
'abstract': boolean;
constructor(settings: ISettings) {
this.name = 'portal';
this.url = '';
this.template = '<div ui-view></div>';
this.abstract = true;
}
}
class ReportsState implements ng.ui.IState {
name: string;
url: string;
templateUrl: string;
'abstract': boolean;
constructor(settings: ISettings) {
this.name = 'portal.reports';
this.url = '/reports';
this.templateUrl = settings.partialsPath + 'reports/partial-reports.html';
this.abstract = true;
}
}
class AdminState implements ng.ui.IState {
name: string;
url: string;
templateUrl: string;
'abstract': boolean;
constructor(settings: ISettings) {
this.name = 'portal.admin';
this.url = '/admin';
this.templateUrl = settings.partialsPath + 'admin/partial-admin.html';
this.abstract = true;
}
}
export class ApplicationRoutingConfig {
public static configure(
$stateProvider: ng.ui.IStateProvider,
$urlRouteProvider: ng.ui.IUrlRouterProvider,
settings: ISettings) {
$urlRouteProvider.otherwise('/reports/generate-reports');
$stateProvider
.state(new RootState(settings))
.state(new ReportsState(settings))
.state(new AdminState(settings));
}
}
}
文件名:routeStatesTests.ts
/// <reference path="../../lib/jasmine/jasmine.d.ts" />
module App {
'use strict';
describe('Application Route States Tests',() => {
beforeEach(() => {
module('ui.router');
module('Application');
});
//beforeEach(module('Application'));
it('should have a ApplicationRoutingConfig controller',() => {
expect(Application.ApplicationRoutingConfig).toBeDefined();
});
it('should initialize ApplicationRoutingConfig',() => {
expect(Application.ApplicationRoutingConfig.configure).toBeDefined();
});
var $stateProvider: ng.ui.IStateProvider;
var $urlRouterProvider: ng.ui.IUrlRouterProvider;
var settings: Application.ISettings = new Application.Settings();
//This is throwing exception
it('should not return empty config',() => {
expect(Application.ApplicationRoutingConfig.configure($stateProvider, $urlRouterProvider, settings)).toNotEqual(null);
});
});
}
我越來越excepti上:
TypeError: Unable to get property 'otherwise' of undefined or null reference at ApplicationRoutingConfig.configure
所有其他測試越來越期待這一個。
任何幫助,將不勝感激!
Dan-有很大幫助,但我注意到'routeStates.ts'沒有返回空的配置,在這裏看到的是編譯的JS代碼: – 2014-10-16 10:06:36
'變種ApplicationRoutingConfig =(函數(){ 函數ApplicationRoutingConfig(){} ApplicationRoutingConfig.configure =函數($ stateProvider,$ urlRouteProvider,設置){$ urlRouteProvider.otherwise( '/報告/生成的報告'); $ stateProvider .state(新的RootState(設置))。state(新的ReportsState(設置))。state(新的AdminState (設置)); }; return ApplicationRoutingConfig; })(); Application.ApplicationRoutingConfig = ApplicationRoutingConfig;' – 2014-10-16 10:07:49
不確定你的意思*注意到routeStates.ts沒有返回空配置*如果引用我的評論'//失蹤?:不應該返回空配置?'我的意思是函數wasn' t返回任何東西,測試失敗,因爲測試期望不是空的 – Dan 2014-10-16 10:53:19