Joe Attardi
Joe Attardi

Reputation: 4521

TypeScript error when running Protractor test

I have a small suite of Protractor tests. In with the tests, I have some page object classes that extend from a common base class. In my protractor config, I have:

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

If I run Protractor with this config, all the tests run. But, if I try to run a single test, I run into an error.

I'm trying to run a specific test with this command:

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

But then I get an error:

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)

Here is the contents of dropdown.po.ts:

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

export const COMPONENT_ID = 'dropdown';

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

There's got to be something I'm missing. Any idea why I get this error when I try to run a single test case, but no error when I run everything? I'm stumped.

Upvotes: 1

Views: 1027

Answers (3)

Joe Attardi
Joe Attardi

Reputation: 4521

I found the necessary fix.

In this case, I needed to add the following to tsconfig.json:

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

Upvotes: 0

Jack
Jack

Reputation: 121

You should run *.js files instead of direct *.ts. Please use tsc for compiling your typescript code to javascript before running tests.

Upvotes: 0

yong
yong

Reputation: 13712

You missed to specify protractor conf in command line:

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

Correct one should be like:

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

Upvotes: 1

Related Questions