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

Logging DOM Document objects causes test failures (PhantomJS, Chrome) #1106

Closed
joshdick opened this issue Jun 20, 2014 · 2 comments · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132
Assignees
Milestone

Comments

@joshdick
Copy link

I have the following basic Mocha test case that runs via Karma:

it.only("shouldn't fail when logging a DOM Document object", function() {
    var parser = new DOMParser();
    var doc = parser.parseFromString("<test></test>", "application/xml");
    console.log(doc); //Causes the test to fail
});

Running the test under PhantomJS triggers a test failure with the following error:

PhantomJS 1.9.7 (Mac OS X)  shouldn't fail when logging a DOM Document object FAILED
    Error: SECURITY_ERR: DOM Exception 18
        at stringify (http://localhost:9876/karma.js:327)
        at stringify (http://localhost:9876/karma.js:327)
        at stringify (http://localhost:9876/karma.js:327)
        at http://localhost:9876/karma.js:107
        at http://localhost:9876/karma.js:85
        ...

A similar but more informative error appears when running the same test in Chrome:

Chrome 35.0.1916 (Mac OS X 10.9.3)  shouldn't fail when logging a DOM Document object FAILED
    Error: Failed to read the 'cookie' property from 'Document': Access is denied for this document.
        at Error (native)
        at stringify (http://localhost:9876/karma.js:327:47)
        at log (http://localhost:9876/karma.js:107:24)
        at Console.localConsole.(anonymous function) [as log] (http://localhost:9876/karma.js:85:16)
        ...

I wouldn't expect doing a console.log() to cause a test failure, but it looks like Karma's internal stringify() function accesses the Document object's cookie property which the browsers don't allow, and hence causes the browsers to throw exceptions which then fail the test.

Is this correct behavior? Should Karma's stringify() function handle this better? Manually running the same code in Chrome's console shows an exception for cookie property alone but still shows the other properties in the object.

(Note: The test code as presented here was simplified, but I ran into this issue by trying to log a backone.js model that referenced a DOM Document object internally.)

@hindsholm
Copy link

I am facing the same problem with a unit test of code that uses DOMParser().
Any chance of a fix for this?

@zarno
Copy link

zarno commented Jul 2, 2015

+1 same issue as @hindsholm

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

Successfully merging a pull request may close this issue.

4 participants