Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 创建和创建pyobj之间有什么区别?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的代码中使用过。
return $provide.decorator('aservice',function($delegatE) {
            $delegate.addFn = jasmine.createSpy().andReturn(true);
            return $delegate;
        });
@H_450_3@那么createSpy在做什么呢?我可以将createSpy@L_874_2@更改为createdpyobj@L_874_2@。

@H_450_3@通过使用createSpy,我们可以创建一个函数/方法mocks。 Createspyobj可以做多个功能模拟。我对吗?

@H_450_3@会有什么区别?

当没有任何功能进行间谍时,可以使用jasmine.createSpy。它将跟踪一个spyOn的呼叫和参数,但没有实现。 @H_450_3@jasmine.createSpyObj用于创建一个可以侦测一个或多个方法的模拟器。它返回一个对象,该对象具有每个作为间谍的字符串的属性

@H_450_3@如果你想创建一个模拟,你应该使用jasmine.createSpyObj。查看下面的例子。

@H_450_3@从茉莉花文档http://jasmine.github.io/2.0/introduction.html

@H_450_3@createSpy:

describe("A spy,when created manually",function() {
  var whatAmI;

  beforeEach(function() {
    whatAmI = jasmine.createSpy('whatAmI');

    whatAmI("I","am","a","spy");
  });

  it("is named,which Helps in error reporTing",function() {
    expect(whatAmI.and.identity()).toEqual('whatAmI');
  });

  it("tracks that the spy was called",function() {
    expect(whatAmI).toHaveBeenCalled();
  });

  it("tracks its number of calls",function() {
    expect(whatAmI.calls.count()).toEqual(1);
  });

  it("tracks all the arguments of its calls",function() {
    expect(whatAmI).toHaveBeenCalledWith("I","spy");
  });

  it("allows access to the most recent call",function() {
    expect(whatAmI.calls.mostRecent().args[0]).toEqual("I");
  });
});
@H_450_3@createSpyObj:

describe("Multiple spies,function() {
  var tape;

  beforeEach(function() {
    tape = jasmine.createSpyObj('tape',['play','pause','stop','rewind']);

    tape.play();
    tape.pause();
    tape.rewind(0);
  });

  it("creates spies for each requested function",function() {
    expect(tape.play).toBeDefined();
    expect(tape.pausE).toBeDefined();
    expect(tape.stop).toBeDefined();
    expect(tape.rewind).toBeDefined();
  });

  it("tracks that the spies were called",function() {
    expect(tape.play).toHaveBeenCalled();
    expect(tape.pausE).toHaveBeenCalled();
    expect(tape.rewind).toHaveBeenCalled();
    expect(tape.stop).not.toHaveBeenCalled();
  });

  it("tracks all the arguments of its calls",function() {
    expect(tape.rewind).toHaveBeenCalledWith(0);
  });
});

大佬总结

以上是大佬教程为你收集整理的angularjs – 创建和创建pyobj之间有什么区别?全部内容,希望文章能够帮你解决angularjs – 创建和创建pyobj之间有什么区别?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。