如何测试一个AngularJS供应商? [英] How can i test a AngularJS provider?

查看:139
本文介绍了如何测试一个AngularJS供应商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试我自己的角度供应商,我需要测试它在这两个配置和运行阶段的检查方法的配置工作,该实例化提供商确实与正确的参数配置。

I need to test my own angular provider, and I need to test it in both config and run phase to check that config methods work and that the instantiated provider is indeed configured with the correct parameters.

当我问依赖关系注入的供应商,它无法找到APIResourceFactoryProvider,只有APIResourceFactory,而我还没有发现任何的例子在我看了低谷至今的存储库。

When I ask dependancy injection for the provider, it can't find the APIResourceFactoryProvider, only the APIResourceFactory, and I haven't found any examples of this on the repositories I've looked trough so far.

推荐答案

这实际上是一个简单得多会比一开始看起来来测试AngularJS提供商:

It's actually a lot simpler than it would at first seem to test a provider in AngularJS:

describe('Testing a provider', function() {
  var provider;

  beforeEach(module('plunker', function( myServiceProvider ) {
      provider = myServiceProvider;
  }));

  it('should return true on method call', inject(function () {
    expect( provider.method() ).toBeTruthy();
  }));
});

```

该证明是在Plunker: http://plnkr.co/edit/UkltiSG8sW7ICb9YBZSH

The proof is in the Plunker: http://plnkr.co/edit/UkltiSG8sW7ICb9YBZSH

这篇关于如何测试一个AngularJS供应商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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