4

After upgrading to version 1.3.5 from 1.3.4 referencing an undefined variable causes the tests to fail. Any suggestions how to disable this behavior? I think its related to js strict mode, that it enables this by default, but cant find a way to disable it

Part of the JsTestDriver.conf file:

load:
  - program.js
  - dialog.js

program.js :

Program = {};

dialog.js :

Program.Dialog = {};

The error message: ReferenceError: Program is not defined

VuesomeDev
  • 4,095
  • 2
  • 34
  • 44
  • Can you say why you don't want the tests to fail if you reference an undefined variable? I would have thought that you would have wanted to fail tests if they tried to reference something that was undefined. – kybernetikos Nov 20 '12 at 07:21
  • legacy code, i dont want to reference undefined variables, but it is not possible to fix it in the near future – VuesomeDev Nov 20 '12 at 11:32
  • Can you show a code snippet whose test passes in 1.3.4 but fails in 1.3.5? – Edgar Villegas Alvarado Nov 25 '12 at 22:11
  • I run the tests with PHPStorm...it seems as if the loading of files became random...in some files i define namespaceslike this: Program.Dialog...but when the files that depend on this namespace loads, fails because the namespace is undefined – VuesomeDev Nov 26 '12 at 16:14
  • The configuration you've shown is fine. Could you email-me a zipped reduced project where this happens? edgarinvillegas@hotmail.com . I know the tool (jsTestDriver and phpstorm) pretty well – Edgar Villegas Alvarado Nov 26 '12 at 18:30

2 Answers2

0

You may be capturing with different browsers now (or different browser setups like console open in IE or strict mode), which are throwing different exceptions now, or probably your codebase has changed since then.

JsTestDriver hasn't changed the behavior for defined/undefined variables treatment for 1.3.5, as it just captures the browser's exceptions.

Anyway, jsTestDriver does not cause a test fail but causes a test error when an undefined variable is referenced.

For example, for this snippet of code in the codebase (asuming undef is an undefined var):

if(undef) alert("foo");

The jsTestdriver output when running the tests from command line is:

Total 2 tests (Passed: 1; Fails: 0; Errors: 1) (1,00 ms)
  Chrome 23.0.1271.64 Windows: Run 2 tests (Passed: 1; Fails: 0; Errors 1) (1,00 ms)
    PersonTest.testWhoAreYou error (0,00 ms): ReferenceError: undef is not defined

As you can see, there was 1 error in the test suite but 0 fails.

EDIT: For your case, it would be possible that jsTestDriver is adding a closure around your name space definition. Try this

Instead of:

var Program = {};

Use:

window.Program = {};

for Program.Dialog you shouldn't have to change anything

Please try that to know if it's the cause.

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61
-1

Best practice is to define your own undefined (jstestdriver.util.undefine;), or to use void 0.

ijse
  • 2,998
  • 1
  • 19
  • 25