Search code examples
javascriptjqueryunit-testingbuster.js

Buster.js dependency error with jQuery: window is not defined


Whenever I attempt to run my unit tests (written with buster and executed user buster test) and include jQuery (since my library depends on it). I get the following error:

./test/deps/jquery-1.7.2.min.js: window is not defined

Here's my buster.js config file: var config = module.exports;

config["GitJs Tests"] = {
    rootPath: "../",
    environment: "node",
    sources: [
        "src/Gitjs.js"
    ],
    deps: [
        "test/deps/*.js" // Jquery is in here
    ],
    tests: [
        "test/test_constructor.js"
    ]
};

Why do I get this error and how do I fix it?


Solution

  • Did some digging and figured out that you get this error because, when running in Node, there is no window. jQuery requires the window object to work properly.

    In short: you can't use jQuery in NodeJs (at least not in its native format :D). If you want to use jQuery and busterJs, you need to run it in "browser" mode.