惩戒角$资源 [英] Mocking Angular $resource

查看:113
本文介绍了惩戒角$资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人建议我的方式如何嘲笑 $资源对象

Could anybody suggest me a way how to mock $resource object

我搜索虽然互联网,但我所有的尝试被KARMA测试完成。
我并不需要它。

I've searched though internet, but all my tries were finished by KARMA testing. I don't need it.

我的想法是刚刚假的对象,所以我将能够在我的应用程序 $资源实现之间进行切换。

My idea is to have just fake object, so I will be able to switch between $resource implementations in my app.

感谢。

推荐答案

您可以使用 $提供来做到这一点。

You can use $provide to do this.

angular.module("MyApp",[])

.config(["$provide",function($provide){

  $provide.decorator("$resource",function($delegate, myReplacementResource){
        //$delegate is the original $resource, if you just want to modify it    

        //either inject a replacement resource that you have already registered
        //as a factory (recommended).  Or make it here.

        return myReplacementResource;

    });

}])

这篇关于惩戒角$资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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