12

My tests are passing from command line, however I edit the typescript source using Atom.

And when I open one of the test files in my editor, I'm seeing an error on this line:

expect(pageObject.name.getText()).toEqual('Some name');

This is the error:

Typescript

Error
Argument of type '"Some name"' is not assignable to parameter of type 'Expected<Promise<string>>'.at line 16 col 50

Why does this show in my editor? Yet tests pass.

Command to run protractor tests:

protractor dist/protractor.config.js

Snippet from package.json

"dependencies": {
    "typescript": "2.3.3"
},
"devDependencies": {
    "@types/jasmine": "2.5.45",
    "@types/node": "^7.0.13",
    "jasmine-core": "^2.6.0",
    "jasmine-spec-reporter": "^4.1.0",
    "protractor": "^5.1.2"
}

tsconfig.fvt.test.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noUnusedParameters": true,
    "outDir": "dist",
    "skipLibCheck": true,
    "target": "ES5",
    "lib": [
      "dom", "es5", "es6", "scripthost"
    ],
    "types": ["jasmine"]
  },
  "include": [
    "protractor.config.ts",
    "test/e2e/**/*.ts"
  ]
}
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150
  • 1
    The Atom TypeScript module tries to read its config from `tsconfig.json`. Check if you have any difference between your `tsconfig.json` and your `tsconfig.fvt.test.json` files. – Maxime Rainville Jun 15 '17 at 23:28
  • 3
    `pageObject.name.getText()` is a promise, so I'm not surprised that this message is shown, although I don't know if the `tsconfig.json` can solve this. You can also first resolve the promise and then do the compare, or use `async/await` like this `expect(await pageObject.name.getText()).toEqual('Some name');` – wswebcreation Jun 16 '17 at 05:07

3 Answers3

5

getText() returns promise. See the doc.

If you want to assert text from an element you need chai-as-promise. See example.

Kacper
  • 1,201
  • 1
  • 9
  • 21
3

Because it is an async method simply change

from expect(pageObject.name.getText()).toEqual('Some name');

to expect(await pageObject.name.getText()).toEqual('Some name');

SushiGuy
  • 1,573
  • 17
  • 20
1

Currently, you can try

npm i "@types/jasminewd2" -D

and add jasminewd2 in your tsconfig.json compilerOptions.types

I met the problem either with protractor. It was the typing bug. Here is the issue link.

xianshenglu
  • 4,943
  • 3
  • 17
  • 34