高效的JavaScript代码单元测试方法(12)

发表于:2013-01-11来源:web开发社区作者:Hazem Saleh点击数: 标签:JavaScript
13 /js- test /TestApplicationUtil.js:29 14 15 ApplicationUtilTest.testValidateLoginFormWithEmptyPassword failed (2.00 ms): 16 AssertError: Password is not validated correctly! expected This field is 1
13     /js-test/TestApplicationUtil.js:29
14  
15     ApplicationUtilTest.testValidateLoginFormWithEmptyPassword failed (2.00 ms): 
16     AssertError: Password is not validated correctly! expected "This field is 
17     required" but was "" Error ("Password is not validated correctly! expected 
18     \"This field is required\" but was \"\"")@:0()@http://localhost:9876/test/
19     js-test/TestApplicationUtil.js:42
20  
21   Safari 534.50 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (2.00 ms)
22   Microsoft Internet Explorer 8.0 Windows: Run 3 tests (Passed: 3; Fails: 0; 
23   Errors 0) (16.00 ms)
24 Tests failed: Tests failed. See log for details.

  注意,在清单 6 中,主要问题出在 Firefox 上。测试在 Internet Explorer 和 Safari 上均可顺利运行。

  修复 JavaScript 代码并重新运行测试用例

  我们来修复损坏的 JavaScript 代码。我们将使用 innerHTML 替代 innerText。清单 7 显示了修复后的 ApplicationUtil 对象代码。

  清单 7. 修复后的 ApplicationUtil 对象代码

  查看源代码

打印帮助
01 appnamespace = {};
02  

原文转自:http://www.ltesting.net