Sunday, 15 April 2012

javascript - How to test jQuery plugin from command line using jasmine and node? -



javascript - How to test jQuery plugin from command line using jasmine and node? -

i have jquery plugin i'm testing. found question: how run jasmine tests on node.js command line? when run:

node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --nocolor spec

i got errors $ not defined. how can include jquery? (right test utilities don't interact dom).

you first need create dom jquery can thing on. should set global variable, accessing jquery (or $) on window element.

first, add together jquery , jsdom package.json file, eg:

"dependencies": { "jquery": "*" }, "devdependencies": { "jsdom": "*" }

run npm install install new dependencies added.

then, @ top of spec file, this:

var jsdom = require("jsdom").jsdom; global.window = jsdom().parentwindow; global.jquery = global.$ = require("jquery")(window);

this creates window element using jsdom, , lets jquery know deed on. should able access both jquery , $ in specs.

javascript jquery node.js jasmine

No comments:

Post a Comment