不能分配给'Expected< Promise< string>>'类型的参数在编辑器中 [英] is not assignable to parameter of type 'Expected<Promise<string>>' in editor

查看:941
本文介绍了不能分配给'Expected< Promise< string>>'类型的参数在编辑器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试是从命令行传递的,但我使用 Atom 编辑 typescript 源。

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');

这是错误:

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

来自的软件包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

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"
  ]
}


推荐答案

getText()返回promise。请参阅 doc

getText() returns promise. See the doc.

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

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

这篇关于不能分配给'Expected&lt; Promise&lt; string&gt;&gt;'类型的参数在编辑器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆