不可分配给编辑器中类型为“Expected<Promise<string>>”的参数

bob*_*e01 10 jasmine typescript protractor

我的测试是从命令行传递的,但是我typescript使用Atom.

当我在编辑器中打开其中一个测试文件时,我在这一行看到一个错误:

expect(pageObject.name.getText()).toEqual('Some name');
Run Code Online (Sandbox Code Playgroud)

这是错误:

Typescript

Error
Argument of type '"Some name"' is not assignable to parameter of type 'Expected<Promise<string>>'.at line 16 col 50
Run Code Online (Sandbox Code Playgroud)

为什么这会显示在我的编辑器中?然而测试通过了。

运行量角器测试的命令:

protractor dist/protractor.config.js
Run Code Online (Sandbox Code Playgroud)

片段来自 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"
}
Run Code Online (Sandbox Code Playgroud)

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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

Kac*_*per 5

getText()回报承诺。请参阅文档

如果你想断言元素中的文本,你需要 chai-as-promise。请参阅示例

  • 难道“expect”函数不应该解决这个承诺吗? (13认同)