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.
MIT License
40 stars 27 forks source link

waitForElement fails with Promise.race is not a function #68

Closed chrsmrtn- closed 7 years ago

chrsmrtn- commented 7 years ago

I'm submitting a bug report

Please tell us about your environment:

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

Expected/desired behavior:

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.

chrsmrtn- commented 7 years ago

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

EisenbergEffect commented 7 years ago

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

chrsmrtn- commented 7 years ago

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.

chrsmrtn- commented 7 years ago

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