angularjs - What is the difference between createspy and createspyobj -



angularjs - What is the difference between createspy and createspyobj -

i have used in code like.

return $provide.decorator('aservice', function($delegate) { $delegate.addfn = jasmine.createspy().andreturn(true); homecoming $delegate; });

in createspy do? can alter createspy calls createspyobj calls.

by using createspy, can create 1 function/method mocks. createspyobj can multiple functions mocks. right?

what difference.

jasmine.createspy can used when there no function spy on. track calls , arguments spyon there no implementation.

jasmine.createspyobj used create mock spy on 1 or more methods. returns object has property each string spy.

if want create mock should utilize jasmine.createspyobj. check out examples below.

from jasmine documentation http://jasmine.github.io/2.0/introduction.html...

createspy:

describe("a spy, when created manually", function() { var whatami; beforeeach(function() { whatami = jasmine.createspy('whatami'); whatami("i", "am", "a", "spy"); }); it("is named, helps in error reporting", function() { expect(whatami.and.identity()).toequal('whatami'); }); it("tracks spy called", function() { expect(whatami).tohavebeencalled(); }); it("tracks number of calls", function() { expect(whatami.calls.count()).toequal(1); }); it("tracks arguments of calls", function() { expect(whatami).tohavebeencalledwith("i", "am", "a", "spy"); }); it("allows access recent call", function() { expect(whatami.calls.mostrecent().args[0]).toequal("i"); }); });

createspyobj:

describe("multiple spies, when created manually", function() { var tape; beforeeach(function() { tape = jasmine.createspyobj('tape', ['play', 'pause', 'stop', 'rewind']); tape.play(); tape.pause(); tape.rewind(0); }); it("creates spies each requested function", function() { expect(tape.play).tobedefined(); expect(tape.pause).tobedefined(); expect(tape.stop).tobedefined(); expect(tape.rewind).tobedefined(); }); it("tracks spies called", function() { expect(tape.play).tohavebeencalled(); expect(tape.pause).tohavebeencalled(); expect(tape.rewind).tohavebeencalled(); expect(tape.stop).not.tohavebeencalled(); }); it("tracks arguments of calls", function() { expect(tape.rewind).tohavebeencalledwith(0); }); });

angularjs jasmine karma-jasmine

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -