lundi 16 novembre 2015

How to New Up a Class in TypeScript

I'm new to TypeScript, but experienced in C#. I'm trying to do something very simple, and I'm missing something fundamental. I'm using Protractor to write User Tests on an Angular front-end. I'm using the Page Object pattern, and I want to keep the Page Object in a separate file from my user tests so I can share the Page Object among several user test files.

I keep getting an error saying the page object class is not a function when I try to new up the class. What am I doing wrong? Here's my code that is failing with the error:

TypeError: UserTests.DashboardPage is not a function.

Page Object File: named dashboard.pageobject.ts

module UserTests {
    export class DashboardPage {
        setupPage = function () {
            console.log("setupPage function");
        };
    }
}

Protractor Test File: name dashboard.test1.spec.ts

/// <reference path="../../../typings/jasmine.d.ts" />
/// <reference path="../../../typings/angular-protractor.d.ts" />
/// <reference path="../../../typings/selenium-webdriver.d.ts" />
/// <reference path="dashboard.pageobject.ts" />

module UserTests {
    describe('When testing the Dashboard page', function() {
        it('Should pass', function () {
            var page = new UserTests.DashboardPage();
        });
    });
}

The error occurs on the line: var page = new UserTests.DashboardPage();

Any help is greatly appreciated! Thanks!

Aucun commentaire:

Enregistrer un commentaire