【问题标题】:TypeScript error when running Protractor test运行 Protractor 测试时出现 TypeScript 错误
【发布时间】:2018-02-02 20:30:37
【问题描述】:

我有一小套量角器测试。在测试中,我有一些从公共基类扩展而来的页面对象类。在我的量角器配置中,我有:

specs: [
  './showcase/e2e/**/*.e2e-spec.ts'
]

如果我使用此配置运行 Protractor,则所有测试都会运行。但是,如果我尝试运行单个测试,则会遇到错误。

我正在尝试使用此命令运行特定测试:

protractor --specs showcase/e2e/app/components/dropdown/dropdown.e2e-spec.ts

然后我得到一个错误:

Error: TSError: ⨯ Unable to compile TypeScript
showcase/e2e/shared/components/dropdown/dropdown.po.ts (3,32): Property 'setPrototypeOf' does not exist on type 'ObjectConstructor'. (2339)

这里是dropdown.po.ts的内容:

import { ExamplePage } from '../example.po';

export const COMPONENT_ID = 'dropdown';

export class DropdownPage extends ExamplePage {
  navigateTo() {
    this.navigateToComponentPage('dropdown');
  }
}

一定是我错过了什么。知道为什么在尝试运行单个测试用例时出现此错误,但在运行所有内容时没有错误吗?我被难住了。

【问题讨论】:

  • 运行整个套件时看起来您使用的是ecma6,但是当您运行单个测试时,它的目标不是您想要的

标签: javascript angular typescript protractor


【解决方案1】:

您错过了在命令行中指定量角器配置:

protractor --specs showcase/e2e/app/components/dropdown/dropdown.e2e-spec.ts

正确的应该是:

protractor conf.js --specs showcase/e2e/app/components/dropdown/dropdown.e2e-spec.ts

【讨论】:

  • 我刚试过,指定我的配置文件,不幸的是我得到了同样的错误。
【解决方案2】:

您应该运行*.js 文件而不是直接运行*.ts。在运行测试之前,请使用tsc 将您的 typescript 代码编译为 javascript。

【讨论】:

  • 我认为这不是问题所在。当我一起运行所有测试(都是用 TypeScript 编写的)时,我没有收到错误。
【解决方案3】:

我找到了必要的修复方法。

在这种情况下,我需要将以下内容添加到tsconfig.json

"lib": [
  "es2016",
  "dom"
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多