我如何模拟局部变量中的服务的功能?茉莉花/噶测试 [英] How do I mock local variable for a function in a service? Jasmine/Karma tests

查看:207
本文介绍了我如何模拟局部变量中的服务的功能?茉莉花/噶测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是角服务有几个功能。他们都充分利用通过定义一个局部变量的 VAR的varName 在文件的顶部。

An Angular service has several functions. All of them make use of a local variable defined via a var varName at the top of the file.

有嘲讽这个变量的任何方式时,单元测试的功能?

Is there any way of mocking this variable when unit-testing the function?

推荐答案

在短期没有。

最简单的方法是把它放在$作用域级别。或者,也许作为一个angularjs恒

The simplest way would be to put it on $scope level. Or Maybe as an angularjs constant

角不变

或者,如果找你一个很疯狂的家伙,你可以​​作出这样的改变变量的值,但严重不这样做,一个剧本,它的疯狂。

Or if you'r a really crazy dude you can make a script that change the value of the var, but seriously don't do that, it's crazy.

这篇关于我如何模拟局部变量中的服务的功能?茉莉花/噶测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆