Jasmine使用命名空间

时间:2014-02-26 15:19:32

标签: javascript namespaces jasmine

我有以下问题。我正在尝试测试一个JS文件,其中包含许多功能。所有这些都有名称空间 x.y.z.function(),但在其中一些我必须调用函数,它在另一个文件中,并具有命名空间x.y.h.function()。问题是当我制作导入脚本时<>在html中,按正确的顺序(检查了100次),最后Jasmine说x.y.h是未定义的,如果我在开头定义它,它说这种方法不存在。看起来它只是在当前文件中搜索,而不是在所有导入的文件中搜索。

我还通过删除所有命名空间来检查它 - 它工作得很好。问题是我无法从任何地方删除命名空间。

参见示例:

    describe("Test core functionality", function () {
it("get_screen_vm",function(){
expect(get_screen("screen_24_34")).not.toBeDefined();
});

检查方法

a.b.c.e.get_screen_vm = function ( unique_s_id ) {

var screen_win = a.b.c.d.get_screen_window_by_unique_id(unique_s_id);

return ( screen_win != undefined ) ? screen_win.values_manager : undefined;
};

HTML

 <script type="text/javascript" src="lib/jasmine-core/jasmine.js"></script>
 <script type="text/javascript" src="lib/jasmine-core/jasmine-html.js"></script>
 <script type="text/javascript" src="lib/jasmine-core/boot/boot.js"></script>
 <script type="text/javascript" src="lib/jquery-1.8.3.min.js"></script>
 <script type="text/javascript" src="lib/mousetrap.min.js"></script>
 <script type="text/javascript" src="init.js"></script>
 <script type="text/javascript" src="gui.js"></script>
 <script type="text/javascript" src="core.js"></script>

 <script type="text/javascript" src="spec/core_specs.js"></script>

现在它给了我:

Error   1   Test 'Test core functionality:screen_vm' failed
    TypeError: 'undefined' is not an object (evaluating 'a.b.c.d.get_screen_window_by_unique_id') in file:///C:/Users/kiril.mladenov/Documents/Aptana%20Studio%203%20Workspace/jasmine/core.js (line 608)
        at file:///C:/Users/kiril.mladenov/Documents/Aptana%20Studio%203%20Workspace/jasmine/ut3_core.js:608
        at file:///C:/Users/kiril.mladenov/Documents/Aptana%20Studio%203%20Workspace/jasmine/spec/ut3_core_specs.js:21
        at attemptSync (file:///C:/Users/kiril.mladenov/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/o3su1t3v.wpt/TestFiles/jasmine/v2/jasmine.js:1510)
        at file:///C:/Users/kiril.mladenov/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/o3su1t3v.wpt/TestFiles/jasmine/v2/jasmine.js:1498
        at file:///C:/Users/kiril.mladenov/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/o3su1t3v.wpt/TestFiles/jasmine/v2/jasmine.js:1485
in C:\Users\kiril.mladenov\Documents\Aptana Studio 3 Workspace\jasmine\spec\ut3_core_specs.js (line 20) C:\Users\kiril.mladenov\Documents\Aptana Studio 3 Workspace\jasmine\spec\core_specs.js  20  

如果以前有人遇到这个问题,我会非常感激。

基里尔

0 个答案:

没有答案