cashay icon indicating copy to clipboard operation
cashay copied to clipboard

String.prototype.startsWith: "undefined is not a constructor"

Open dustinfarris opened this issue 9 years ago • 11 comments

I'm running acceptance tests in Ember. The tests pass in Chrome, however when I run the tests in Phantom JS, I am getting this error:

TypeError: undefined is not a constructor (evaluating 'type.startsWith('@@cashay')')

which seems to stem from this line:

https://github.com/mattkrick/cashay/blob/27320c4ebd5c5d2ce697479d21a72de7f3d7c73c/src/normalize/duck.js#L38

Any idea what might cause this?

dustinfarris avatar Oct 31 '16 16:10 dustinfarris

Did you set up the redux store for your tests?

On Oct 31, 2016 9:18 AM, "Dustin Farris" [email protected] wrote:

I'm running acceptance tests in Ember. The tests pass in Chrome, however when I run the tests in Phantom JS, I am getting this error:

TypeError: undefined is not a constructor (evaluating 'type.startsWith('@@cashay')')

which seems to stem from this line:

https://github.com/mattkrick/cashay/blob/27320c4ebd5c5d2ce697479d21a72d e7f3d7c73c/src/normalize/duck.js#L38

Any idea what might cause this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjvzlg9SpBdX7iO2aQU7o_PtLkLUtZks5q5hS4gaJpZM4KlM5O .

mattkrick avatar Oct 31 '16 17:10 mattkrick

Think I figured it out. It is because PhantomJS does not support String.prototype.startsWith. I am trying to find a polyfill I can inject.

dustinfarris avatar Oct 31 '16 17:10 dustinfarris

Whoa! Thats interesting. I could use indexOf, startsWith is just a little more expressive

On Oct 31, 2016 10:33 AM, "Dustin Farris" [email protected] wrote:

Think I figured it out. It is because PhantomJS does not support String.prototype.startsWith. I am trying to find a polyfill I can inject.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136#issuecomment-257362422, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjv1OfRk6TKOe6-9DV5p8klsIKYHkvks5q5iaBgaJpZM4KlM5O .

mattkrick avatar Oct 31 '16 17:10 mattkrick

Here's a polyfill you could add to cashay's dependencies: https://github.com/mathiasbynens/String.prototype.startsWith

dustinfarris avatar Oct 31 '16 17:10 dustinfarris

But now getting the same thing for Object.prototype.find

e.g.: https://github.com/mattkrick/cashay/blob/8d9174d478b63883f68b64f82c183b60a3aad0c4/src/normalize/denormalizeStore.js#L56

This may be something I as a user should be responsible for polyfilling (I wonder if babel polyfill would make all of this go away).

dustinfarris avatar Oct 31 '16 17:10 dustinfarris

Yeah, running everything through babel polyfill makes this all go away.

~~This can be closed as far as I'm concerned, unless there is any docs action you think would be appropriate.~~

dustinfarris avatar Oct 31 '16 17:10 dustinfarris

I am hitting this again, this time in plain-ol node

var transformSchema = require('cashay').transformSchema;

transformSchema(myRootSchema...

results in

TypeError: undefined is not a function
    at /Users/dustin/Archive/broccoli-cashay-schema/node_modules/cashay/lib/schema/transformSchema.js:127:23

stemming from: https://github.com/mattkrick/cashay/blob/master/src/schema/transformSchema.js#L39

dustinfarris avatar Nov 25 '16 18:11 dustinfarris

ah, now that we don't have the polyfill, it doesn't have startsWith?

mattkrick avatar Nov 25 '16 19:11 mattkrick

Correct—if I install/require the polyfill mentioned above everything works. What do you think about doing this in cashay instead?

Add String.prototype.startsWith to dependencies and in index.js:

import 'string.prototype.startsWith';

(not sure how the dots in the name will affect import)

and/or via babel-polyfill (again) — but it would be a devDependency this time just to generate lib/

dustinfarris avatar Nov 25 '16 19:11 dustinfarris

Well the fact that I was using node v0.12.6 probably wasn't helping 👎

What minimum version of node do we want to support?

dustinfarris avatar Nov 25 '16 19:11 dustinfarris

I'd say 6 LTS, although I think 4 would work

On Nov 25, 2016 11:24 AM, "Dustin Farris" [email protected] wrote:

Well the fact that I was using node v0.12.6 probably wasn't helping 👎

What minimum version of node do we want to support?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136#issuecomment-263013660, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjv5tJpz05i337_BywMyy2l_yqHsq9ks5rBzXogaJpZM4KlM5O .

mattkrick avatar Nov 25 '16 20:11 mattkrick