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.
Previously the code below would run no problem because window was
[object DOMWindow] but since the upgrade it's become [object global]
(and no longer respects my jasmine mock)
if (window.confirm("unit testing?")) {
this.ajaxStuff();
}
If anyone knows why I get a global now instead of DOMWindow that would
be great, but even bigger might be how I should protect myself from
the "window" keyword itself.
I'm only writing browser based javascript so I don't see a huge
problem with using window, but if I need to abstract it should I just
make it an input for each JS object I'm building so I don't have to
patch it as I'm doing now? Or is this a non issue for browser based
javascript code?
**test snippet for the above
it("should do ajax stuff and make something hidden", function(){
window = jsdom.jsdom("<html><head></head><body></body></
html>").createWindow();
var sut = new SomeObjectUnderTest();
expect($jqueryObject).toBeVisible();
spyOn(window, 'confirm').andReturn(true);
sut.doSomeClickEvent();
expect($('#something')).not.toBeVisible();
});
(cross posted from stackoverflow) - link below
http://stackoverflow.com/questions/10304494/how-to-properly-isolate-jasmine-unit-tests-from-window-using-jsdom
--
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