Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in PhantomJS #107

Closed
tonovotny opened this issue Nov 6, 2012 · 9 comments
Closed

Problem in PhantomJS #107

tonovotny opened this issue Nov 6, 2012 · 9 comments

Comments

@tonovotny
Copy link

With change delivered with fixing #86 I'm unable to use Chai in PhantomJS (1.7) getting this error in output:

RangeError: Maximum call stack size exceeded.

When I replace new non-empty setter:

Object.defineProperty(Object.prototype, 'should',
                  {
                    set: function (value) {
                        // See https://github.com/chaijs/chai/issues/86: this makes
                        // `whatever.should = someValue` actually set `someValue`, which is
                        // especially useful for `global.should = require('chai').should()`.
                        //
                        // Note that we have to use [[DefineProperty]] instead of [[Put]]
                        // since otherwise we would trigger this very setter!
                        Object.defineProperty(this, 'should', {
                            value: value,
                            enumerable: true,
                            configurable: true,
                            writable: true
                        });
                      }
...

with old (empty) one:

Object.defineProperty(Object.prototype, 'should',
                  {
                    set: function () { }
...

everything works fine.

Running in regular browser is fine either way.

@domenic
Copy link
Contributor

domenic commented Nov 6, 2012

Does this occur with basic, simple tests or assertions? Or can you narrow this down to some particular test? For example I can see how this would be problematic if you were relying on everyObjectInTheWorld.should = anything to be a no-op before, because now it isn't.

@tonovotny
Copy link
Author

I've just tried the most minimal test without loading my app modules and libs and it seems to be working. I'm currently busy with other work but I will try adding stuff step by step and let you know when the problem arises.

@logicalparadox
Copy link
Member

I did some testing with PhantomJs and got this same error. It looks like this occurs if you try to assign should as a global (on window). The work around that I found was to just var should = chai.should() in a script block before including my tests.

As far as I have seen this only happens with PhantomJS.

Here is a sample mocha html file for use with mocha-phantomjs:

<!DOCTYPE html>
<html>
  <head>
    <title>Browser Tests</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
    <script src="../../node_modules/mocha/mocha.js"></script>
    <script src="../../node_modules/chai/chai.js"></script>
    <script src="../../build/build.js"></script>
    <script>
      mocha.setup('bdd')
      var should = chai.should();
    </script>
    <script src="../test.js"></script>
    <script>
      onload = function () {
        if (window.mochaPhantomJS) mochaPhantomJS.run()
        else mocha.run();
      }
    </script>
  </head>
  <body>
    <div id="mocha"></div>
  </body>
</html>

@tonovotny
Copy link
Author

That was exactly the problem, thank you!

My app (including tests) is divided to AMD modules generated by TypeScript compiler. I put only "var should;" to outer scope in "entry-point" js file and tests are running.

Thank you again ;) I really appreciate your work.

@tb
Copy link

tb commented Mar 11, 2014

Hi, I had similar issue with

var should = chai.should()

causing

RangeError: Maximum call stack size exceeded.
  # chai.js:3344

for me fix was simply

chai.should()

@seansfkelley
Copy link

If you need to expose it on window for whatever reason, you can work around it by stubbing out the should field and then immediately reassigning it. This seems to circumvent the problematic property-creation step and keeps just the assignment:

window.should = undefined;
window.should = chai.should();

@reubano
Copy link

reubano commented May 8, 2014

Why is this issue closed? The problem still exists.

@gasolin
Copy link

gasolin commented Jun 20, 2014

check #107 (comment) , which works

@reubano
Copy link

reubano commented Jun 30, 2014

Yes, but it's a work-around. The bug is still there, either in chai or phantom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants