Jasmine does not reset spy after each test spec
jasmine, javascript, junit, testing, unit-testing
Solution
I had the same problem some time ago and after days of struggling I found the solution. If you use the other way your spy will be reseted, so try with
spyOn(SN, 'Utils');
Spies are described here: https://github.com/pivotal/jasmine/wiki/Spies
Problem
I have the following spec. ``` describe("SN.ExitHistory", function() { var exitHistory; beforeEach(function() { SN.Utils = jasmine.createSpy("utils").andCallFake(function() { function readSNCookie(cookieName, key) { return "google.com"; } function isUndefinedOrNull(param) { return (param == null) || (param === "null"); } function createSNCookie(snCookieName, key, value, lifeTime) { } var me = { readSNCookie : readSNCookie, isUndefinedOrNull : isUndefinedOrNull, createSNCookie : createSNCookie }; return me; })(); exitHistory = SN.ExitHistory(); }); it("return last exit link", function() { expect(exitHistory.getLastExitLink()).toEqual("google.com"); }); }); ``` `exitHistory.getLastExitLink` internally use `SN.Utils`. After the test is done Jasmine does not remove the spy object utils. In next test suite also I can see the same utils present. Is there any way to reset the spy object after each test is done? Instead of creating spy, if I create a new object for utils, behavior is same. Then what is the difference between a spy and actual object in this scenario. Correct me if I am wrong.