Saw this question but renaming to jQuery doesn't help.

I'm trying to get some basic unit-testing in Webstorm to work. Even without the tests it's not finding things defined in other files.

I have this config file:

server: http://localhost:9876

load:
  - libs/jquery-1.9.0.min.js
  - src/jquery.combine/jquery.combine.js

But it get this error when running the tests:

error loading file: /test/src/jquery.combine/jquery.combine.js:2: Uncaught TypeError: Cannot set property 'union' of undefined

The path's are a bit different, but clicking it show's the right file.

jquery.combine.js looks like this:

(function($) {
  $.union = function () {
    // ...
  };
}(jQuery));

Why is it not detecting jQuery? It includes it correctly because if I misspell the path it complains about missing file instead.

有帮助吗?

解决方案

I was able to solve this with the help of JetBrains. Somehow this solves itself if you add a jsTestDriver adapter for QUnit. WebStorm comes bundled with this one.

My updated jsTestDriver.conf looks like this:

load:
 - libs/qunit-jstd-adapter/equiv.js
 - libs/qunit-jstd-adapter/QUnitAdapter.js
 - libs/jquery/jquery.js
 - src/*.js

test:
 - test/*.js

I'm pasting the instructions I got from JetBrains (with slight modification) which helped me solve the issue:

1) delete jquery.combine/libs/qunit/qunit.js - doing so will make symbols 'test' and 'module' unresolved,

2) open jquery.combine/test/difference.tests.js and position test cursor on any 'test' function call, wait alittle and you'll see the suggestion: "Add QUnit JsTestDriver adapter? Alt+Enter" Invoking this quick fix will open a dialog, where you should specify a directory where "QUnit JsTestDriver Adapter" files will be added.

3) As equiv.js and QUnitAdapter.js files are located inside your project, load them in jsTestDriver.conf

4) Now right-click jsTestDriver.conf and select run (JsTestDriver server should be up and have a captured browser).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top