I am new to TypeScript, but experience in C #. I am trying to make something very simple, and I am missing something fundamental. I use Protractor to write custom tests on the Angular interface. I am using a page object template, and I want to save the page object in a separate file from my user tests so that I can share the page object among several user test files.
I keep getting an error saying that the page object class is not a function when I try to create a new class. What am I doing wrong? Here is my code that does not work with 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");
};
}
}
Prototype Test File: dashboard.test1.spec.ts Name
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 ();
UPDATE (11/17/15):
I finally put all the pieces together after reading basarat's answer about internal modules. I removed the module keyword from the page object file, made the setupPage method public, and added an import statement to the specification file. Reading about external modules made me realize that Node treats each file as a module already. This message (also on basarat) led me to discover this feature. In addition, I installed RequireJS. Here is my final code.
Page Object File:
export class DashboardPage {
public setupPage = function () {
console.log("setupPage function");
};
}
Run codeHide resultTest file prototype:
import pageObj = require("./dashboard.pageobject");
describe('When testing the Dashboard page', function() {
it('Should pass', function () {
var page = new pageObj.DashboardPage();
page.setupPage();
console.log('I made it!');
});
});
Run codeHide resultI thank the people who responded!