On Wed, Apr 25, 2012 at 11:28 AM, toranb <[email protected]> wrote:

> I've been using jasmine to unit test my javascript the last few
> months. I've been running these tests with node (v4) jsdom/jasmine-
> node/jasmine-jquery
>
> Everything was fine until I had to upgrade from node v4 -I did a make
> install from the 6.11 build and noticed that I had to update jsdom.
>




> jsdom and or jsdom + node seems to have changed how it views the
> "window" keyword.
>

is this in the context of jsdom's script executor or node's? I'm assuming
the former, but that is still weird.  The jsdom script context doesn't
define a 'global' variable.  It is more likely that the string
representation of a window is incorrect.

Here's how I came to that conclusion:

Code:

require('jsdom').env({
  html : "<html><head></head><body></body></html>",
  src  : "window.stringified = window + ''; window.typeofGlobal = typeof
global; window.keys = Object.keys(window)",
  done : function(err, window) {
    console.log('[jsdom context] window.stringified:', window.stringified,
'\n');
    console.log('[jsdom context] typeof global:', window.typeofGlobal,
'\n');
    console.log('[jsdom context] window.keys:',
JSON.stringify(window.keys), '\n');
    console.log('[node context] window === global: ' + (window === global),
'\n');
  }
});


Output:

tmp‣ node window-global.js
[jsdom context] window.stringified: [object global]

[jsdom context] typeof global: undefined

[jsdom context] window.keys:
["location","addEventListener","removeEventListener","dispatchEvent","raise","setTimeout","setInterval","clearInterval","clearTimeout","__stopAllTimers","run","getGlobal","dispose","top","parent","self","frames","window","document","stringified","typeofGlobal","_length","length","close","getComputedStyle","console","navigator","XMLHttpRequest","name","innerWidth","innerHeight","outerWidth","outerHeight","pageXOffset","pageYOffset","screenX","screenY","screenLeft","screenTop","scrollX","scrollY","scrollTop","scrollLeft","alert","blur","confirm","createPopup","focus","moveBy","moveTo","open","print","prompt","resizeBy","resizeTo","scroll","scrollBy","scrollTo","screen","Image","languageProcessors","resourceLoader","HTMLCollection","HTMLOptionsCollection","HTMLDocument","HTMLElement","HTMLFormElement","HTMLLinkElement","HTMLMetaElement","HTMLHtmlElement","HTMLHeadElement","HTMLTitleElement","HTMLBaseElement","HTMLIsIndexElement","HTMLStyleElement","HTMLBodyElement","HTMLSelectElement","HTMLOptGroupElement","HTMLOptionElement","HTMLInputElement","HTMLTextAreaElement","HTMLButtonElement","HTMLLabelElement","HTMLFieldSetElement","HTMLLegendElement","HTMLUListElement","HTMLOListElement","HTMLDListElement","HTMLDirectoryElement","HTMLMenuElement","HTMLLIElement","HTMLDivElement","HTMLParagraphElement","HTMLHeadingElement","HTMLQuoteElement","HTMLPreElement","HTMLBRElement","HTMLBaseFontElement","HTMLFontElement","HTMLHRElement","HTMLModElement","HTMLAnchorElement","HTMLImageElement","HTMLObjectElement","HTMLParamElement","HTMLAppletElement","HTMLMapElement","HTMLAreaElement","HTMLScriptElement","HTMLTableElement","HTMLTableCaptionElement","HTMLTableColElement","HTMLTableSectionElement","HTMLTableRowElement","HTMLTableCellElement","HTMLFrameSetElement","HTMLFrameElement","HTMLIFrameElement","_augmented","INVALID_STATE_ERR","SYNTAX_ERR","INVALID_MODIFICATION_ERR","NAMESPACE_ERR","INVALID_ACCESS_ERR","StyleSheet","MediaList","CSSStyleSheet","CSSRule","CSSStyleRule","CSSMediaRule","CSSImportRule","CSSStyleDeclaration","StyleSheetList","mapper","mapDOMNodes","visitTree","markTreeReadonly","INDEX_SIZE_ERR","DOMSTRING_SIZE_ERR","HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","INVALID_CHARACTER_ERR","NO_DATA_ALLOWED_ERR","NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INUSE_ATTRIBUTE_ERR","exceptionMessages","DOMException","NodeList","DOMImplementation","Node","NamedNodeMap","AttrNodeMap","NotationNodeMap","EntityNodeMap","Element","DocumentFragment","ProcessingInstruction","Document","CharacterData","Attr","Text","Comment","CDATASection","DocumentType","Notation","Entity","EntityReference"]

[node context] window === global: false


So as you can see above, the window object does have all of the expected
props/method and it is not the same as node's global object.

I hope that helps, and if you do find a sidecase please report it (
https://github.com/tmpvar/jsdom/issues)

Oh, and for future reference there is a mailing list for jsdom specific
issues/questions (http://groups.google.com/group/jsdom)

-- Elijah

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to