aurelia / testing

Simplifies the testing of UI components by providing an elegant, fluent interface for arranging test setups along with a number of runtime debug/test helpers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

waitForElement fails with Promise.race is not a function

chrsmrtn- opened this issue · comments

I'm submitting a bug report

  • Library Version:
    1.0.0-beta.3.0.1

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    7.4.0

  • NPM Version:
    4.3.0
  • JSPM OR Webpack AND Version
    N/A
  • Browser:
    Chrome 59, Firefox 54

  • Language:
    all

Current behavior:
When attempting to use component.waitForElement I get an error saying "Promise.race is not a function"

Expected/desired behavior:

  • What is the expected behavior?
    Expecting waitForElement to work in both when the element is available and even under a timeout condition

  • What is the motivation / use case for changing the behavior?
    unit testing the display of a sub-component so the waitForElement is used to wait until the bindings to trickle through until the show.bind of the sub-component is processed and the 'aurelia-hide' class is removed and the element is displayed.

Further testing and information
I've taken both the typescript and esnext base projects created from the latest Aurelia-CLI (0.30.0 as of this ticket) and modified the app.spec.ts unit test. I added the following line to check if the race function is indeed defined.

console.log('promise.race: ' typeof Promise.race);

Then upon running the test, the log messaged logged in the console window reads:

promise.race: undefined

I'd imagine i'm expecting this to report that it is of type function as in the waitFor.js code we return a Promise.race.

Current tsconfig.json file when testing. I noted that I was targeting es5 and I believe Promise.race was introduced with es6.
tsconfig.json.txt - target es5

Then I tried updating my tsconfig.json to target es6 and I still got the same results
tsconfig.json.txt - target es6

If you want to use Promise.race, you need a polyfill that includes that. It's unrelated to Aurelia.

Thanks @EisenbergEffect ! I'm using bluebird polyfill. This was all tested too under the base esnext and typescript projects using Aurelia CLI. Maybe I'm missing a configuration option that I need to enable in those project to get the Promise.race to work? I'll do some more digging.

Okay got it fixed! Thanks again @EisenbergEffect for pointing me in the right direction. In my environment I'm using a project that was generated from Aurelia CLI. This project naturally includes bluebird, but it uses the bluebird.core.js file which doesn't include the Promise.race function. Once I adjusted the Aurelia.json file so it references bluebird.js instead, I now have access to Promise.race in all browers.

A bit of info I didn't realize before. Once you use bluebird, it acts as the "go between" for all browsers. I thought the bluebird polyfill would only be loaded in IE and we'd just use native Promises in other browsers. But this is not the case. All browsers use the bluebird polyfill