简体   繁体   中英

undefined is not a constructor

I am using rails 4, capybara, poltergeist to test my rails 4 + angularjs app. In my angular app, there is a place I have the below code in my directive controller.

var audience = [someObject1, someObject2, someObject3].findIndex(function(object) {
  return object.id === 1;
});

I got the following error during test

Error: undefined is not a constructor (evaluating '[1,2,3].findIndex(function(v) { return v === 1; })')

actually it won't even allow me to have something like this

[1, 2, 3].findIndex(function(v) {
  return v === 1;
});

anyone knows why poltergeist doesn't like the find and findIndex method of Javascript?

find and findIndex are ES6 methods and probably not supported by phantomJs. If you're not running phantomjs 2.1.1 you can try updating to that, otherwise you can either load polyfills using the extensions option in your poltergeist driver config, or rewrite your code to not use ES6 methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM