Я хотел бы спросить вас, как я могу проверить класс, который принимает экземпляр конструктора другого класса. Например я хочу, чтобы проверить 'hasChildRoutes() метод:Тестирование классов TypeScript с Jasmine
class Route implements ng.route.IRoute {
public url: string;
public config: RouteConfig;
constructor(url: string, config: RouteConfig) {
this.url = url;
this.config = config;
}
public hasChildRoutes(): boolean {
return this.config.childRoutes.length > 0;
}
}
я написал плохой модульное тестирование для этого (им создавать новые экземпляры других классов, которые плохо на мой взгляд):
beforeEach(() => {
routeSetting = new RouteSetting(1, '');
routeConfig = new RouteConfig('', '', routeSetting, [], '');
});
describe('Methods test',() => {
var childRoute: Route;
beforeEach(() => {
route = new Route('', routeConfig);
});
it('sould return false when Route has no child routes',() => {
expect(route.hasChildRoutes()).toBeFalsy();
});
it('sould return true when Route has child routes',() => {
routeConfig = new RouteConfig('', '', routeSetting, [route], '');
route = new Route('', routeConfig);
expect(route.hasChildRoutes()).toBeTruthy();
});
});