【发布时间】:2014-12-07 01:08:53
【问题描述】:
我在测试我用 TypeScript 编写的有角度的东西时遇到了一个奇怪的异常,这是我的两个文件:
文件名: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);
});
});
}
我遇到了异常:
TypeError: Unable to get property 'otherwise' of undefined or null reference at ApplicationRoutingConfig.configure
除此之外,所有其他测试都已通过。
对此的任何帮助将不胜感激!
【问题讨论】:
标签: angularjs tdd typescript jasmine bdd