koral koral - 1 month ago 66
TypeScript Question

Writting e2e tests (Protractor, Jasmine) using typescript

What should I add to

package.json
and import in each
e2e.spec.ts
file to have such a possibility?

Currently when I change
e2e.spec.js
to
e2e.spec.ts
the file is compiled and I have errors saying
Cannot find name 'browser'
etc.

I tried to

import {browser, element, by} from 'protractor';


but then during compilation I've got errors

node_modules/protractor/built/browser.d.ts(1,1): error TS1084:
Invalid 'reference' directive syntax.


My
package.json
(only important parts)

{
"scripts": {
"lite": "lite-server",
"tsc": "tsc",
"typings": "typings",
"pree2e": "npm run webdriver:update",
"webdriver:update": "webdriver-manager update"
},
"dependencies": {
"@angular/common": "~2.0.1",
"@angular/compiler": "~2.0.1",
"@angular/core": "~2.0.1",
"@angular/forms": "~2.0.1",
"@angular/http": "~2.0.1",
"@angular/platform-browser": "~2.0.1",
"@angular/platform-browser-dynamic": "~2.0.1",
"@angular/router": "~3.0.1",
"@angular/upgrade": "~2.0.1",
"angular2-in-memory-web-api": "0.0.20",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"canonical-path": "0.0.2",
"concurrently": "^3.0.0",
"jasmine": "^2.5.2",
"jasmine-fail-fast": "^2.0.0",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.0.2",
"lite-server": "^2.2.2",
"protractor": "^4.0.8",
"protractor-jasmine2-screenshot-reporter": "^0.3.2",
"typescript": "^1.8.10",
"typings": "^1.4.0"
}
}


and sample test suite

// import {browser, element, by} from 'protractor';
describe('Test suite related with health tab', () => {
beforeEach(function () {
browser.get('');
});
}

Answer

I had to upgrade typescript to >= 2.0.0 and downgrade protractor to 3.3. Then I don't have to add any import to e2e-spec.ts.

Comments