Protractor: Typings issue since @types/jasmine update

Created on 22 Mar 2017  Â·  10Comments  Â·  Source: angular/protractor

Since the release of @types/[email protected] I have this issue while running my protractor tests with typescript:

[18:37:17] E/launcher - Error: TSError: ⨯ Unable to compile TypeScript
e2e/app.e2e-spec.ts (19,45): Argument of type '"Hello world !"' is not assignable to parameter of type 'Expected<Promise<string>>'. (2345)

This trace back to this code:

    expect(page.getParagraphText()).toEqual('Hello world !');

In the new jasmine types, the expect typings are now enforced (it wasn't the case before).
It seems that the protractor jasmine overrides that wait for Promises to resolve before performing the match needs to extends the typings for this to work correctly.

Bug report

  • Node Version: 6.x
  • Protractor Version: 5.x
  • Angular Version: 2.x
  • Browser(s): PhantomJS
  • Operating System and Version osx 10.12.11

Most helpful comment

@ChristianStornowski Thanks, I found why it wasn't working!

I'm using angular-cli and the default e2e package.json config has:

    "types": [
      "jasmine",
      "node"
    ]

changing it to:

    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]

make it work!

All 10 comments

Thanks for noting this.

Can you pin your types in the meantime to resolve this?

Sure, it's already done 😉
Thanks for this great tool anyways!

yep :-(

I also observed this
e2e/app.e2e-spec.ts(23,54): error TS2345: Argument of type 'false' is not assignable to parameter of type 'Expected<Promise<boolean>>'.

for the line
expect(element(by.css('h1')).isPresent()).toBe(false);

Downgraded jasmine typings to
"@types/jasmine": "2.5.45"

For Jasmine tests you can use @types/jasminewd2 additionally to @types/jasmine.

expect(
to
expect(

its worked for me

@ChristianStornowski still not working even with @types/jasminewd2

Here are my settings for package.json

... "devDependencies": { ... "@types/jasmine": "^2.5.52", "@types/jasminewd2": "^2.0.2", "jasmine-core": "^2.6.4", "typescript": "^2.3.4", ... } ...

for tsconfig.json

{ "compilerOptions": { "target": "es5", "module": "CommonJS", "moduleResolution": "Node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "outDir": "build", "strictNullChecks": true, "lib": [ "DOM", "ES5", "ES6", "ES7", "DOM.Iterable", "ScriptHost" ] } }

This is working with current IntellIJ for me.

@ChristianStornowski Thanks, I found why it wasn't working!

I'm using angular-cli and the default e2e package.json config has:

    "types": [
      "jasmine",
      "node"
    ]

changing it to:

    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]

make it work!

Any updates after 13 months guys ?

@mruzek What kind of update do you expect? There is nothing broken here.

You have two options:

  • Install @types/jasminewd2 as pointed out above and keep using Protractor with SELENIUM_PROMISE_MANAGER: true (not recommended solution, because it is deprecated, has pile of drawbacks and will be removed eventually).
  • Set SELENIUM_PROMISE_MANAGER: false and use async/await syntax instead (recommended solution, see docs here).
Was this page helpful?
0 / 5 - 0 ratings