Javascript 如何使用jasmine对钛合金控制器中的功能进行单元测试
控制器功能: controllerexample.jsJavascript 如何使用jasmine对钛合金控制器中的功能进行单元测试,javascript,unit-testing,titanium,jasmine,titanium-alloy,Javascript,Unit Testing,Titanium,Jasmine,Titanium Alloy,控制器功能: controllerexample.js function test() { return "works!"; }; 控制器示例_specs.js it('test controllerexample function.', function() { $ = Alloy.createController('controllerexample', {}); expect($.test).toEqual('works!'); }); 运行脚本时,出现以下
function test() {
return "works!";
};
控制器示例_specs.js
it('test controllerexample function.', function() {
$ = Alloy.createController('controllerexample', {});
expect($.test).toEqual('works!');
});
运行脚本时,出现以下错误:
[ERROR] : . THERE WERE FAILURES!
[ERROR] : . ============================================================
[ERROR] : . Recap of failing specs:
[ERROR] : . ------------------------------------------------------------
[ERROR] : . controllerexample controller test controllerexample function.. - Expected Function to equal 'works!'
尝试将其更改为$.test。对于初学者,请查看这是否会更改任何东西。如果我像这样设置我的函数,请注意:$.test=函数{return true;};否则它会抱怨它没有定义。我是否总是必须以这种方式公开它?当我尝试与代码中列出的相同操作时,我会失败:1 util测试遇到声明异常消息:ReferenceError:Alloy未定义Stacktrace:ReferenceError:Alloy未定义为null。在0.005秒内完成1次测试、1次断言、1次失败、0次跳过