jasmine / jasmine-gem

Jasmine ruby gem
682 stars 274 forks source link

Ensure we stingify complex objects before sending it to ruby #309

Closed stoivo closed 4 years ago

stoivo commented 5 years ago

Continues work on #301

JQuery objects could not be stringified. It would trow a exception: TypeError: Converting circular structure to JSON

The error example includes a Jquery element with DOM reference so it cant be stringyfied out of the box. toArray() on jquery elements is lossy but it works and I did need it to fix my errors.

fix #306

stoivo commented 5 years ago

I will add a spec next time i have time to dedicate some time to this PR. Will be in touch.

Should I commit a minified version of jQuery?

slackersoft commented 5 years ago

We definitely don't want to include a version of jQuery inside Jasmine. It looks like your error message actually does say that the cause is a circular reference in the object being converted to JSON. The easiest "fix" (in the linked example above) is to just try/catch around the JSON.stringify call and return a string that indicates the circular reference. This would also solve the issue for users using other Javascript frameworks, not just jQuery.

stoivo commented 4 years ago

Sorry for taking so long. We use the patch for out system and it works do we did spend any more time on this. I took some time this weekend do fix this and hopyfully an other PR too.

stoivo commented 4 years ago

I will do some more reseach so see If I can get it working with https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value.

Are you fine with dropping support for rails4 since it reached end of life?

stoivo commented 4 years ago

I will open a new PR when it is ready