English 中文(简体)
"namespace is undefined" problem when using jsTestDriver, Idea 9 and testing 3 test cases. Sometimes it just outright hangs
原标题:

I just started using jsTestDriver and I really like it, but all of a sudden, I just started getting a very weird error and I m not sure what the heck I did to create it. Actually, if I try and run a basic Greeter test, the same problem happens.

Here s an example of one of my javascript files/classes under test:

myapp = myapp || {};

myapp.Module = function() {
    ...
};

All of the classes follow this pattern.

My test classes generally look like this (I ll give a really simple one):

ModuleTest = TestCase("ModuleTest");

ModuleTest.prototype.testInit = function() {
    var module = new myapp.Module(); // <---- it bombs here, on every test!

    assertFalse(module.isStarted);

    module.init();

    assertTrue(module.isStarted);
};

It bombs when it gets to "new myapp.Module()". Here is the error message that is given about 30 times for all my tests:

myapp is not defined
/src/test/webapp/js/ModuleTest.js:4

Here is my configuration file:

server: http://localhost:9876

load:
  - src/main/webapp/js/jquery/*.js
  - src/main/webapp/js/*.js
  - src/test/webapp/js/*.js

Does anyone have any idea what the heck is wrong? Sometimes when I run all the tests in IDEA, my IDE just hangs altogether or takes like many minutes for jsTestDriver to finally report the above results...

:(

问题回答

I faced the same issue after I moved to v.1.3.1. In my case the problem was with file encoding. I use Visual Studio for the development, it adds byte order mark (3 extra bytes) in the beginning of the file. It s possible to see these bytes in Far manager. If you use VS try to save the file as the following: "File->Advanced save options->" Encoding: Unicode (UTF-8 without signature) - Codepage 65001. It should fix your problem.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签